Kontrollstrukturen

if-Block

In [5]:
a = 1
b = 4
In [6]:
if 2*a < b:
    var = 15.4
    var2 = "1. if-Block"
elif a > 2*b:
    var = 5.4
    var2 = "2. elif-Block"
else:
    var = 20.4
    var2 = "3. else-Block"
print(var)
print(var2)
15.4
1. if-Block

Schleifen

In [7]:
a = 'Anfang'
b = 0x0a
c = 'Ende'
In [11]:
for w in [a,b,c]:
    if isinstance(w, str):
        erg = " ".join([hex(ord(i))[2:] for i in w])
    elif isinstance(w, int):
        erg = chr(w)
        w = hex(w)
    print("w={},erg={}".format(w,repr(erg)))
w=Anfang,erg='41 6e 66 61 6e 67'
w=0xa,erg='\n'
w=Ende,erg='45 6e 64 65'
In [12]:
%%writefile test.txt
Anfang
Ende
Writing test.txt
In [13]:
!hexdump -C test.txt
00000000  41 6e 66 61 6e 67 0a 45  6e 64 65                 |Anfang.Ende|
0000000b