dr Bogna Zacny
Katedra Inżynierii Wiedzy
Wydział Informatyki i Komunikacji
python
cena = 10
print(type(cena))<class 'int'>
cena = 10
print(type(cena))<class 'int'>
cena = 10 + 0.9
print(type(cena))cena = 10
print(type(cena))<class 'int'>
cena = 10 + 0.9
print(type(cena))<class 'float'>
cena = 10
print(id(cena))14071341129120
cena = 10 + 0.9
print(id(cena))140713411291232
import thisComplex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
zmienna w pythonie to nazwa nadana wartości lub kolekcji wartości
zmienna w pythonie to nazwa nadana wartości lub kolekcji wartości
-> operator przypisania
=
zmienna w pythonie to nazwa nadana wartości lub kolekcji wartości
=
-> operator przypisania
nazwa = wartosc
wzrost = 1.7
print(f'Wzrost Janka wynosi {wzrost}')wzrost = 1.7
waga = 70
print(waga / wzrost**2)wzrost = 1.7
waga = 70
bmi = waga / wzrost**2
print(bmi)Atomowe
Kolekcje
Atomowe
tekstowe
a = 'python'
b = '1'
c = '.'Atomowe
tekstowe
a = 'python'
b = '1'
c = '.'liczbowe
a = 123
b = 12.3
c = 0.8721
Atomowe
tekstowe
liczbowe
logiczna
a = False
b = Truea = 'python'
b = '1'
c = '.'a = 123
b = 12.3
c = 0.8721
Atomowe
Kolekcje
lista =>[ ]
a = ['mój', 'samochód', 'mój', 'wybór']
b = ['Uczelnia', 'UEwK-ce', 2019]
c = [1, 1, 2, 3, 4.5, 1201, 1]Kolekcje
lista =>[ ]
d = 'Meritum'a = ['mój', 'samochód', 'mój', 'wybór']
b = ['Uczelnia', 'UEwK-ce', 2022]
c = [1, 1, 2, 3, 4.5, 1201, 1]Kolekcje
-> string
zbiór =>{ }
a = {'samochód', 'mój', 'wybór'}
b = {'Uczelnia', 'UEwK-ce', 2019}
c = {1, 2, 3, 4.5, 1201}
lista =>[ ]
a = ['mój', 'samochód', 'mój', 'wybór']
b = ['Uczelnia', 'UEwK-ce', 2022]
c = [1, 1, 2, 3, 4.5, 1201, 1]Kolekcje
krotka =>( )
a = ("Jan", "Kowalski", "80010103754")
zbiór =>{ }
a = {'samochód', 'mój', 'wybór'}
b = {'Uczelnia', 'UEwK-ce', 2019}
c = {1, 2, 3, 4.5, 1201}
lista =>[ ]
a = ['mój', 'samochód', 'mój', 'wybór']
b = ['Uczelnia', 'UEwK-ce', 2022]
c = [1, 1, 2, 3, 4.5, 1201, 1]Kolekcje
słowik =>{:}
a = {'imię': 'Jan', 'nazwisko': 'Nowak', 'wiek': 23}
b = {'dok1': ['mój', 'samochód', 'mój', 'wybór'],
'dok2': ['mocna', 'herbata', 'na', 'nastrój']}
dok1 = {'mój': 2, 'samochód': 1, 'wybór': 1}
Kolekcje
[ 'Thor', 'Storm', 'Wolverine', 'Hulk', 'Wasp' ]
[ 'Thor', 'Storm', 'Wolverine', 'Hulk', 'Wasp' ]
[ 'Thor', 'Storm', 'Wolverine', 'Hulk', 'Wasp' ]
[ 'Storm', 'Wolverine']
[ 'Thor', 'Storm', 'Wolverine', 'Hulk', 'Wasp' ]
Indeksowanie
[ 'Thor', 'Storm', 'Wolverine', 'Hulk', 'Wasp' ]
Indeksowanie
[ 'Thor', 'Storm', 'Wolverine', 'Hulk', 'Wasp' ]
0
1
2
3
4
Indeksowanie
[ 'Thor', 'Storm', 'Wolverine', 'Hulk', 'Wasp' ]
0
1
2
3
4
[]
-> operator wycinania
[ 'Thor', 'Storm', 'Wolverine', 'Hulk', 'Wasp' ]
0
1
2
3
4
[]
lista[indeks]
-> operator wycinania
[ 'Thor', 'Storm', 'Wolverine', 'Hulk', 'Wasp' ]
0
1
2
3
4
[]
lista[indeks]
lista[start:stop]
-> operator wycinania
Pętla iteracyjna =>
Pętla repetycyjna =>
forwhilefor [każdego_elementu] in [kolekcji]: wykonaj_instrukcje
Pętla iteracyjna
for i in range(5):
print(i)
Pętla iteracyjna
forfor i in range(5):
print(i)
Pętla iteracyjna
0 1 2 3 4
forfor i in [11,22,33]:
print(i)
Pętla iteracyjna
11 22 33
forfor i in 'ABC':
print(i)
Pętla iteracyjna
A B C
forliczby = [1,2,3,4]
for liczba in liczby:
potega = liczba * liczba
print(potega)
Pętla iteracyjna
1
4
8 16
forliczby = [1,2,3,4]
potegi = []
for liczba in liczby:
potega = liczba * liczba
potegi.append(potega)
print(potegi)
Pętla iteracyjna - tworzenie nowej kolekcji
[1, 4, 9, 16]
Instrukcja warunkowa =>
ifif [zapytanie warunkowe]: wykonaj_instrukcje_jeżeli_True
if [zapytanie warunkowe]: wykonaj_instrukcje_jeżeli_True
if [zapytanie warunkowe]: wykonaj_instrukcje_jeżeli_True else: wykonaj_instrukcje_jeżeli_False
if x > 0:
print('Liczba jest dodatnia')ifif x > 0:
print('Liczba jest dodatnia')
else:
print('Liczba jest ujemna')if x > 0:
print('Liczba jest dodatnia')ifif
elseif x > 0:
print('Liczba jest dodatnia')if x > 0:
print('Liczba jest dodatnia')
else:
print('Liczba jest ujemna')if x > 0:
print('Liczba jest dodatnia')
elif x == 0:
print('Zero')
else:
print('Liczba jest ujemna')ifif
elseif
elif
elseR
G
B
0-255
0-255
0-255
50
91
113
Dziękuje za uwagę
bogna.zacny@uekat.pl