-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex32.py
More file actions
46 lines (42 loc) · 1.45 KB
/
ex32.py
File metadata and controls
46 lines (42 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#Pętle i listy
the_count = [1,2,3,4,5]
fruits = ['jabłka', 'pomarańcze', 'gruszki', 'morele']
change = [1, 'jednogroszówki', 2, 'dwugroszówki', 3, 'pięciogroszówki']
#to jest pierwszy rodzaj pętli for, która przechodzi przez listę
for number in the_count:
print(f"To jest licba {number}")
#to samo co wyżej
for fruit in fruits:
print(f"Rodzaje owocu: {fruit}")
#możemy również przechodzić przez listy mieszane
#zwróć uwagę, że musimy uzyć {}, ponieważ nie wiemy co wniej jest
for i in change:
print(f"Mam {i}")
#możemy również budować listy, zaczniemy od pustej
elements = []
for i in range(0, 6):
print(f"Dodajmy {i} do listy.")
#append dodanie elementu na koniec (jest to funkcja którą listy rozumieją)
elements.append(i)
#teraz możemy je wydrukować
for i in elements:
print(f"Tym elementem było: {i}")
#określenie ilość elementów listy
print("ilośc elementów listy: "+str(len(elements)))
#metoda insert() dodadnia elementu o określonym ideksie
elements.insert(2, 22)
print(f"insert(2, 22) {elements}")
#metoda remove() usunięcie z listy określonego elementu
elements.remove(2)
print(f"remove(2) {elements}")
#metoda pop() usunięcie określonego indeksu
elements.pop(2)
print(f"pop(2) {elements}")
#metoda copy() skopiowianie listy
new_elements = elements.copy()
#metoda list() skopiowanie listy
new_elements = list(elements)
print(new_elements)
#clear wyczyszczenie listy
elements.clear()
print(elements)