36
1 The First Few Steps
run for hours, days, and even weeks. Fast code is tremendously important in those
cases.
The problem with a strong focus on fast code, unfortunately, is that sometimes
clear and easily understandable constructions are replaced by fast (and possibly
clever), but less readable code. For beginners, however, it is definitely most
important to learn writing readable and correct code.
We will make some comments on constructions that are fast or slow, but the main
focus of this book is to teach how to write correct programs, not the fastest possible
programs.
1.8.4 Deleting Data No Longer in Use
Python has automatic garbage collection, meaning that there is no need to delete
variables (or objects) that are no longer in use. Python takes care of this by itself.
This is opposed to, e.g., Matlab, where explicit deleting sometimes may be required.
1.8.5 Code Lines That Are Too Long
If a code line in a program gets too long, it may be continued on the next line
by inserting a back-slash at the end of the line before proceeding on the next line.
However, no blanks must occur after the back-slash! A little demonstration could be
the following,
my_sum = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 +\
14 + 15 + 16 + 17 + 18 + 19 + 20
So, the back-slash works as a line continuation character here.
1.8.6 Where to Find More Information?
We have already recommended Langtangen’s book, A Primer on Scientific Programming with Python (Springer, 2016), as the main reference for the present book.
In addition, there is, of course, the official Python documentation website
(http://docs.python.org/), which provides a Python tutorial, the Python Library
Reference, a Language Reference, and more. Several other great books are also
available, check out, e.g., http://wiki.python.org/moin/PythonBooks.
As you do know, search engines like Google are excellent for finding information
quickly, so also with Python related questions! Finally, you will also find that the
questions and answers at http://stackoverflow.com often cover exactly what you
seek. If not, you may ask your own questions there.
Précédent

- 58/350

Suivant