Lecture 04
Lecture 04
print(f'{h}:{m}:{s}')
Statement
Unlike expressions, a statement does not return data as a result
Basic: e.g. storing the value of an expression, deleting an item from a collection of data
Compound: composed of other statements
Slicing
Accessing multiple elements at once,
'Hello World!'
"A"
>>> L = [111,222,333,444,555,666]
>>> L[1:5] = []
>>> print(L)
[111, 666]
>>> L = [111,222,333,444,555,666]
>>> del L[1:5]
>>> print(L)
[111, 666]
Concatenation and repetition with lists and tuples: Similar to strings, + and * operators can be used
>>> print(d["karsiyaka"])
35.5
True
{2, 3, 4, 9}
The following are only applicable with sets (and not with forezensets):
S.add(element): Add a new element to the set.
◦ Use i, j, k, m, n for counting only: Programmers implicitly recognize them as integer holding
(the historical reason for this dates to 60 years ago).
◦ Use x, y, z for coordinate values or multi-variate function arguments.
◦ If you are going to use multiple words for a variable, choose one of
these:
◦ Put all words into lowercase, affix them using _ as separator (e.g. highest_midterm_grade,
shortest_path_distance_up_to_now).
◦ Put all words but the first into first-capitalized-case, put the first one into lowercase, affix them
without using any separator (e.g. highestMidtermGrade,
shortestPathDistanceUpToNow).
◦ You cannot use reserved words, such as and, def from, is, continue, print…
>>> age = 20
>>> height = 1.70
>>> eye_color = "brown"
>>> print(f"I am {height} tall, {age} years old and have {eye_color} eyes")
I am 1.7 tall, 20 years old and have brown eyes
you may use the following methods: index(), insert(), reverse(), count(), remove(), sort(), len()
'name': "alexandra",
'age': 29,
'is_premium_member': True
read a key from the user and print the corresponding value
add a new entry with the 'orders' key which is a list of tuples that contains ordered items
and their prices, e.g. [('pen', 10) , ('book', 15)]
update the value of age