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

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

Bild der Seite - 43 -

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

Text der Seite - 43 -

2.2 Variables,ObjectsandExpressions 43 In [1]: x = 2 In [2]: y = 4.0 In [3]: s = ’hello’ In [4]: type(x) # ...object named x is an integer Out[4]: int In [5]: type(y) # ...object named y is a float Out[5]: float In [6]: type(s) # ...object named s is a string Out[6]: str Type Conversion Objects may be converted from one type to another if it makes sense. If, e.g.,x is thenameofanintobject,writing In [1]: x = 1 In [2]: y = float(x) In [3]: y Out[3]: 1.0 shows thaty thenbecomesa floatingpoint representationofx. Similarly,writing In [1]: x = 1.0 In [2]: y = int(x) In [3]: y Out[3]: 1 illustrates thatybecomesan integer representationofx. Note that theint function rounds down, e.g., y = int(1.9) also makes y become the integer 1. Type conversionmayalsooccurautomatically. 2.2.5 AutomaticTypeConversion What if weaddafloat object to an intobject?We could,e.g.,write In [1]: x = 2 In [2]: x = x + 4.0 In [3]: x Out[3]: 6.0 What happens here, is that automatic type conversion takes place, and the new x will have thevalue6.0, i.e., refer to anobjectof typefloat.
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