Vorlesung 2
This commit is contained in:
29
Vorlesung 2/variablen.py
Normal file
29
Vorlesung 2/variablen.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# Variablen und Datentypen
|
||||
|
||||
a = True # Datentyp bool
|
||||
b = False
|
||||
print("a =", a, "Type: " , type(a))
|
||||
|
||||
char1 = 'A' # Datentyp char
|
||||
char2 = '!'
|
||||
char3 = '#'
|
||||
print("char1 =", char1, "Type: " , type(char1))
|
||||
|
||||
satz = "Hallo Welt!" # Datentyp string
|
||||
print("satz =", satz, "Type: " , type(satz))
|
||||
|
||||
zahl1 = 4 # Datentyp Integer speichert ganze Zahlen
|
||||
print("zahl1 =", zahl1, "Type: " , type(zahl1))
|
||||
|
||||
zahl2 = 3.5 # Datentyp float
|
||||
print("zahl2 =", zahl2, "Type: " , type(zahl2))
|
||||
print("zahl1 =", zahl1, "Speicher-Adresse: ", id(zahl1))
|
||||
print("zahl2 =", zahl2, "Speicher-Adresse: ", id(zahl2))
|
||||
|
||||
# zahl3 verweist jetzt auf die gleiche speicheradresse wie zahl1
|
||||
zahl3 = zahl1
|
||||
print("zahl3 =", zahl3, "Speicher-Adresse: ", id(zahl3))
|
||||
|
||||
# Typenkonvertierung:
|
||||
zahl3 = str(zahl1)
|
||||
print("zahl3 =", zahl3, "Type: " , type(zahl3))
|
||||
Reference in New Issue
Block a user