37 lines
761 B
Python
37 lines
761 B
Python
# Kommentar
|
|
|
|
# Strings
|
|
|
|
bla = 'das ist ein schöner Schdring\n \
|
|
nächste Zeile'
|
|
print(bla)
|
|
print(bla[2:10]) # Substring
|
|
print(bla[:3] + bla[-6:]) # erstes und letztes Wort
|
|
|
|
# List
|
|
werte = [ 3, 6, 23, 34, 56.3, 35.6]
|
|
print(werte)
|
|
werte.append(23) # returns none
|
|
print(werte)
|
|
werte[2] = 4 # mutable, with index
|
|
print(werte)
|
|
|
|
# Fibonacci
|
|
a, b = 0, 1 # multiple assignment
|
|
while a < 10:
|
|
print(a, end=':') # Schleifenbody ist eingerückt
|
|
a, b = b, a + b
|
|
|
|
print("\n -- Primzahlensuche:")
|
|
|
|
# Primzahlensuche mit for .. else!
|
|
for n in range(2, 10):
|
|
for x in range(2, n):
|
|
if n % x == 0:
|
|
print(n, "equals", x, "*", n//x)
|
|
break
|
|
else:
|
|
# keinen Faktor gefunden (innere Schleife)
|
|
print(n, "ist Primzahl")
|
|
|