Tuple Unpacking

[2]:
l = ['joerg', 'flo', 'ted', 'rainer']
for element in l:
    print(element)
joerg
flo
ted
rainer
[3]:
d = {
    'joerg': 54,
    'ted': 56,
    'rainer': 55,
}
[5]:
for element in d:
    print(element)
joerg
ted
rainer
[8]:
for key in d.keys():
    print(element)
rainer
rainer
rainer
[10]:
for value in d.values():
    print(value)
54
56
55
[12]:
for element in d.items():
    print(element)
('joerg', 54)
('ted', 56)
('rainer', 55)
[16]:
for element in d.items():
    key = element[0]
    value = element[1]
    print(f'key: {key}, value: {value}')
key: joerg, value: 54
key: ted, value: 56
key: rainer, value: 55
[19]:
for key, value in d.items():
    print(f'key: {key}, value: {value}')
key: joerg, value: 54
key: ted, value: 56
key: rainer, value: 55
[22]:
t = ('joerg', 54)
name, age = t
print(f'name: {name}, age: {age}')
name: joerg, age: 54
[27]:
a = 1
b = 2
a, b
[27]:
(1, 2)
[28]:
b, a = a, b
[30]:
a, b
[30]:
(2, 1)

String Methods

[31]:
s = 'joerg'
[33]:
s.capitalize()
[33]:
'Joerg'
[35]:
s
[35]:
'joerg'
[37]:
s.upper()
[37]:
'JOERG'
[39]:
s.upper().lower()
[39]:
'joerg'
[41]:
s.center(60)
[41]:
'                           joerg                            '
[43]:
s.find('rg')
[43]:
3
[45]:
s.find('xxx')
[45]:
-1
[1]:
l = ['joerg', 'faschingbauer']
'.'.join(l)
[1]:
'joerg.faschingbauer'

Strings vs. Bytes

[4]:
s = 'Jörg'
b = b'Joerg'
[8]:
try:
    s + b
except Exception as e:
    print(type(e), e)
<class 'TypeError'> can only concatenate str (not "bytes") to str
[10]:
s == b
[10]:
False
[11]:
7 == '7'
[11]:
False
[ ]: