# Typy danych

• mutowalne i niemutowalne
• wszystko jest obiektem
• referencje na instancje

# Instrukcje warunkowe

• if, else, elif
• x if x > 5 else 10
• brak switch case
``````

In [ ]:

zmienna = "nic"
if zmienna == "nic":
print("nic")

``````
``````

In [ ]:

if "a" in ["a", 2, 3]:
print("element w kolekcji")

``````
``````

In [ ]:

if "a" in set(["a", 2, 3]):
print("element w kolekcji")

``````
``````

In [ ]:

a = 10
if 5 < a < 20:
print("a w zakresie 5 i 20")

``````
``````

In [ ]:

a = 10
if a in range(20):
print("w zakresie do 20")

``````
``````

In [ ]:

mapa = {
"a": 5,
"b": 10,
"c": 20
}

print("a" in mapa)

``````
``````

In [ ]:

mapa = {
"a": 5,
"b": 10,
"c": 20
}

if "e" not in mapa:
print("mapa nie posiada elementu")

``````
``````

In [ ]:

class Point():
pass

a = Point()
b = Point()

print(a is b)
print(a == b)

``````
``````

In [ ]:

a = None
if a is not None:
print("zrob cos")

x = True
y = False

if not y and x:
print(x, y)

print(y and x)

``````
``````

In [ ]:

a = 10

if a < 5:
print("a w zakresie do 5")
elif a > 10:
print("a wieksze od 10")
else:
print("jak nie spelnia warunkow to tutaj")

``````
``````

In [ ]:

liczba = 10
a = liczba if liczba > 5 else -5
b = liczba if liczba > 20 else -5
print(a)
print(b)

``````

# Pętle

• tylko dwie pętle for i while
• for - iteracja po obiektach iterowalnych
• while - iteracja warunkowa
``````

In [ ]:

for index, element in enumerate(range(10, 50, 10)):
print(index, element)

``````
``````

In [ ]:

for element in range(len([1, 2, 3, 4, 5])):
print(element)

``````
``````

In [ ]:

for element in range(len([1, 2, 3, 4, 5])):
if element == 2:
break
print(element)

``````
``````

In [ ]:

for element in range(len([1, 2, 3, 4, 5])):
if element == 2:
continue
print(element)

``````
``````

In [ ]:

for element in range(len([1, 2, 3, 4, 5])):
pass

``````
``````

In [ ]:

for element in range(len([1, 2, 3, 4, 5])):
print(element)
else:
print("blok kodu w else")

``````
``````

In [ ]:

for element in range(len([1, 2, 3, 4, 5])):
print(element)
if element == 2:
break
else:
print("blok kodu w else")

``````
``````

In [ ]:

for element in range(len([1, 2, 3, 4, 5])):
print(element)
if element == 2:
continue
else:
print("blok kodu w else")

``````
``````

In [ ]:

a = 5
while a > 0:
print(a)
a = a - 1

``````

# range i xrange

• python2 xrange - iterator
• python2 range - zwraca liste
• python3 brak xrange, range - iterator
``````

In [ ]:

list(range(5))

``````
``````

In [ ]:

list(range(0, 10, 1))

``````
``````

In [ ]:

list(range(10, 1, -1))

``````
``````

In [ ]:

list(range(10, 1, -1))[::2]

``````