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 - 40 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

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

Bild der Seite - 40 -

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

Text der Seite - 40 -

40 2 AFewMoreSteps Observe that, as in a program, certain items must be imported before use, e.g.,pi, sin,cos, etc.Forexample, to interactivelycomputesin(π2), youcouldwrite In [1]: from math import sin, pi In [2]: sin(pi/2) Out[2]: 1.0 Observe that the import statement here, i.e. from math import sin, pi, is an exampleof input thatdoesnotproduceanycorrespondingoutput. Youmayalso definevariablesanduse formulas interactivelyas In [1]: v0 = 5 In [2]: g = 9.81 In [3]: t = 0.6 In [4]: y = v0*t - 0.5*g*t**2 In [5]: print(y) 1.2342 2.1.2 CommandHistory IPythonstores thedialogue,whichallowsyoutoeasily repeatapreviouscommand, with or without modifications. Using the up-arrow key, brings you “backwards” in commandhistory.Pressing thisone timegivesyou thepreviouscommand,pressing two timesgivesyou the commandbefore that, andso on.With the down-arrowkey you can go “forward” again. When you have the relevant command at the prompt, youmayedit it beforepressingenter (which letsPythonread it and take action). 2.1.3 TABCompletion When typing in IPython, you may get assistance from the TAB key to finalize a variablenameorcommandyouare typing. To illustrate, assume youhavewritten In [1]: import numpy as np In [2]: x = np.lins # before pressing TAB key and then press the TAB key. IPython will then assume you intend to write np.linspaceand thereforefill out the rest foryou, so thatyousuddenlyhave In [2]: x = np.linspace # after pressing TAB key Youmay thengoonandfill out the rest, perhaps like In [2]: x = np.linspace(0, 1, 11) # after filling out the rest
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