Web-Books
im Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Seite - 41 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

Seite - 41 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Bild der Seite - 41 -

Bild der Seite - 41 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Text der Seite - 41 -

2.2 Variables,ObjectsandExpressions 41 Generally, if you press the TAB key “too early”, IPython might have to give you a list ofoptions, fromwhichyoumaychoose the intendedword. With longer words, or if you are a bit uncertain about the spelling, TAB completion is a handytool. 2.2 Variables,ObjectsandExpressions 2.2.1 ChooseDescriptiveVariableNames Namesof variables should be chosenso that they are descriptive. If youare coding some formula that in mathematical writing containsx and y, x and y ought to be the corresponding names for those variables in your code (unless there are special considerationsforyourcase). Sometimes it isdifficult,orevenimpossible, tohaveavariablenamein thecode that is identical to the corresponding mathematical symbol. Some inventiveness is then called for, as, for example, when we used the variable name v0 for the mathematical symbol v0 in our first program ball.py. Similarly, if you need a variable for the counting of sheep, one appropriate name could beno_of_sheep, i.e., join well-chosenwords by use of an underscore.2 Such naming makes it much easier for a human to understand the written code, which in turn makes it easier to finderrorsormodify thecode.Variablenamesmayalsocontainanydigit from0to 9,orunderscores,butcannot start withadigit.Lettersmaybe loweroruppercase, which to Python isdifferent. 2.2.2 ReservedWords Note that certainnames inPythonare reserved, meaning that youcannot use these as names for variables. Interactively, we may get a complete list of the reserved words: In [1]: import keyword In [2]: keyword.kwlist Out[2]: [’False’, ’None’, ’True’, ’and’, ’as’, ’assert’, ’break’, ’class’, ’continue’, ’def’, ’del’, ’elif’, ’else’, ’except’, ’finally’, ’for’, ’from’, ’global’, ’if’, ’import’, ’in’, ’is’, ’lambda’, ’nonlocal’, ’not’, ’or’, ’pass’, ’raise’, ’return’, ’try’, ’while’, ’with’, ’yield’] As you can see, we have met some of these already, e.g.,fromandimport. If you accidentallyuse a reservedwordasavariablenameyougetan errormessage. 2 Another common way of joining words into variable names, is to start each new word with a capital letter, e.g., like in noOfSheep. In this book, however, we stick to the convention with underscores.
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Titel
Programming for Computations – Python
Untertitel
A Gentle Introduction to Numerical Simulations with Python 3.6
Band
Second Edition
Autoren
Svein Linge
Hans Petter Langtangen
Verlag
Springer Open
Datum
2020
Sprache
englisch
Lizenz
CC BY 4.0
ISBN
978-3-319-32428-9
Abmessungen
17.8 x 25.4 cm
Seiten
356
Schlagwörter
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Kategorie
Informatik
Web-Books
Bibliothek
Datenschutz
Impressum
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python