-
Notifications
You must be signed in to change notification settings - Fork 8
/
22_krotki.py
53 lines (37 loc) · 1006 Bytes
/
22_krotki.py
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
47
48
49
50
51
52
53
# Krotki sa podobne do list, ale nie mozna ich modyfikowac
krotka = (1, 2, 3, 4, 5)
print(krotka)
# krotka[0] = 10 # TypeError: 'tuple' object does not support item assignment
# Krotki sa szybsze od list
from timeit import timeit
print(
timeit("krotka = (1, 2, 3, 4, 5)", number=1000000)
) # timeit zwraca czas w sekundach
print(timeit("lista = [1, 2, 3, 4, 5]", number=1000000))
# Krotki sa uzyteczne do zwracania wielu wartosci z funkcji
def funkcja():
return 1, 2, 3
print(funkcja())
print(type(funkcja()))
# Krotki mozna rozpakowywac
a, b, c = funkcja()
print(a)
print(b)
print(c)
# Krotki mozna laczyc
krotka1 = (1, 2, 3)
krotka2 = (4, 5, 6)
print(krotka1 + krotka2)
# Krotki mozna mnozyc
print(krotka1 * 3)
# Krotki mozna indeksowac
print(krotka1[0])
print(krotka1[-1])
print(krotka1[1:3])
print(krotka1[1:])
# sprawdzanie czy element jest w krotce
print(1 in krotka1)
# dlugosc krotki
print(len(krotka1))
# zliczanie wystapien elementu w krotce
print((1, 1, 2, 1).count(1))