Skip to main content Accessibility help
×
Hostname: page-component-7c8c6479df-7qhmt Total loading time: 0 Render date: 2024-03-28T14:25:31.522Z Has data issue: false hasContentIssue false

3 - A Short Python Tutorial

Published online by Cambridge University Press:  02 August 2017

John M. Stewart
Affiliation:
University of Cambridge
Get access

Summary

Although Python is a small language, it is a very rich one. It is very tempting, when writing a textbook, to spell out all of the ramifications, concept by concept. The obvious example is the introductory tutorial from the originator of Python, Guido van Rossum. This is available in electronic form as the tutorial in your Python documentation or on-line or as hard copy (van Rossum and Drake Jr. (2011)). It is relatively terse at 150 printed pages, and does not mention NumPy. My favourite textbook, Lutz (2013), runs to over 1500 pages, a marathon learning curve, and mentions NumPy only in passing. It is excellent at explaining the features in detail, but is too expansive for a first course in Python. A similar criticism can be applied to two books with a more scientific orientation, Langtangen (2009) and Langtangen (2014), both around 800 pages, with a significant overlap between them. I recommend these various books among many others for reference, but not for learning the language.

Very few people would learn a foreign language by first mastering a grammar textbook and then memorizing a dictionary. Most start with a few rudiments of grammar and a tiny vocabulary. Then by practice they gradually extend their range of constructs and working vocabulary. This allows them to comprehend and speak the language very quickly, and it is the approach to learning Python that is being adopted here. The disadvantage is that the grammar and vocabulary are diffused throughout the learning process, but this is ameliorated by the existence of textbooks, such as those cited in the first paragraph.

Typing Python

Although the narrative can simply be read, it is extremely helpful to have the IPython terminal to hand, so that you can try out the code samples. For longer code snippets, e.g., those in Sections 3.9 and 3.11, it is advisable to use either notebook mode, or terminal mode together with an editor, so that you can save the code. Your choices are described in Sections A.2 and A.3 of Appendix A.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2017

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

Available formats
×