What will be the result:
-> w
->
Warum?
Das Leerzeichen hat die geringsten ASCII coe points
Result?
-> d
Built-in Function
Default Parameters:
Output?
2,3,4,5,6,7,8,9
-> 10 is the value where is stops so it needs to be range(2,11) to get the to printed as well
Are both options working?
Yes
Why is the ‘is’ operator stronger than the == operator
== checks equality
is checks object identity
So every time a is b is true, you typically also have a == b true, but not the other way around:
Can we use the break and continue keywords in for loops as well?
Write a while loop that prints out the integers 2 through 10.
Both working?
No, only the first one. Len is not a string function, but a build in
looping through strings, while
len = 6 index = 0 -> 0,1,2,3,4,5 -> 6 iterations
looping through strings with ‘for
How is the , treated in output text?
My name is Luca and I am 24 -> , is a space
Separating mutliple arguments
Printing with style:
0 = 47.42, 1 = 11
-> 3d means that 11 wil be printed as an integer in 3 character wide field
-> 7.2f means that 47.42 will be printed as float in a field that is 7 charatcters wide. with 2 decimals (Nachkommastellen)
The width expands if the number doesn’t fit
Format float as ineteger, does it work?
Format integer as float, does it work?
-> No “ValueError: Unknown format code 'd' for object of type 'float'“
-> Yes, converts int to float
Printing with sytle inclusing positional arguments
Why is the first onw working but not the second one?
doeky = 0, somkey = 1 have positional arguments, okey has a keyword argument
-> positional arguments net to come before the keyword arguments, that’s why the second one is not working
Slicing Strings
check if char in word
in operator
>>> fruit = 'banana'
>>> 'n' in fruit
string comparison
a is before b in alpabet therefore it’s index is smaller
other string functions
searching a string
find() function
-> 2
search and replace in a string
-> Hello Jane
stripping whitecases
-> ‘Hello Maria ‘
->‘ Hello Maria’
-> ‘Hello Maria’
split a string
-> ['Hello', 'Joao,', 'How','are', 'you?’]
-> [' Hello Joao', ' How are you?‘]
-> [' Hell', ' J', 'a', ', H', 'w are y', 'u? ']
checking how a string starts
string.startswith(‘Please’)
>>> line = 'Please have a nice day'
>>> line.startswith('Please')
-> True
How to extract this part of the text
Last changed15 days ago