Book contents
- Frontmatter
- Contents
- Preface to the Second Edition
- Preface to the First Edition
- 1 Introduction
- 2 Getting Started with IPython
- 3 A Short Python Tutorial
- 4 NumPy
- 5 Two-Dimensional Graphics
- 6 Multi-Dimensional Graphics
- 7 SymPy: A Computer Algebra System
- 8 Ordinary Differential Equations
- 9 Partial Differential Equations: A Pseudospectral Approach
- 10 Case Study: Multigrid
- Appendix A Installing a Python Environment
- Appendix B Fortran77 Subroutines for Pseudospectral Methods
- References
- Hints for Using the Index
- Index
3 - A Short Python Tutorial
Published online by Cambridge University Press: 02 August 2017
- Frontmatter
- Contents
- Preface to the Second Edition
- Preface to the First Edition
- 1 Introduction
- 2 Getting Started with IPython
- 3 A Short Python Tutorial
- 4 NumPy
- 5 Two-Dimensional Graphics
- 6 Multi-Dimensional Graphics
- 7 SymPy: A Computer Algebra System
- 8 Ordinary Differential Equations
- 9 Partial Differential Equations: A Pseudospectral Approach
- 10 Case Study: Multigrid
- Appendix A Installing a Python Environment
- Appendix B Fortran77 Subroutines for Pseudospectral Methods
- References
- Hints for Using the Index
- Index
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
- Python for Scientists , pp. 21 - 54Publisher: Cambridge University PressPrint publication year: 2017
- 3
- Cited by