Skip to content

Commit a3cd68a

Browse files
committed
feat: add update & multiplication explanations
1 parent 87a7eb8 commit a3cd68a

5 files changed

Lines changed: 29 additions & 35 deletions

File tree

notes/lambda.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Не требует def и имени функции;
55
- Может содержать только одно выражение (не инструкции);
66
- Часто применяется для кратких операций: сортировки, фильтрации, небольших преобразований.
7+
lambda аргументы: выражение
78
"""
89
square = lambda x: x * x
910
print(square(5)) # 25

notes/multiplication.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
List or tuple can be initiated by multiplication
3+
"""
4+
x = (0,)*3
5+
print(x) # (0, 0, 0)
6+
y = [1]*3
7+
print(y) # [1, 1, 1]

notes/shallow_copy.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@
1010

1111
print(c[1] is b[1] is a) # True
1212
# Мы обращаемся напрямую к объектам внутри массива и сравниваем их, shallow copy копирует ссылки на объекты
13-
14-
# c = b[:] created a shallow copy, so c and b are not the same object. Both still reference a.
13+
"""
14+
x = [[0]] * 3 - cоздаёт один список (shallow copy), а затем три раза повторяет ссылку на один и тот же
15+
вложенный список, а не создаёт 3 независимых списка.
16+
"""
17+
x = [[0]] * 3
18+
print(x) # [[0], [0], [0]]

notes/test.py

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,7 @@
1-
class Rogen:
2-
def __secret(self):
3-
return "hackme1337"
1+
x = [[0]]*3
2+
print(x)
43

5-
def registr(self):
6-
login = "Egor\n" + self.__secret()
7-
return login
8-
9-
r = Rogen()
10-
print(r.registr())
11-
try:
12-
print(r.__secret())
13-
except AttributeError:
14-
print('HERE IS NOTHING!!!')
15-
# class Map:
16-
# def __init__(self):
17-
# self.__geek()
18-
19-
# def geek(self):
20-
# print("In parent class")
21-
22-
# # private copy of original geek() method
23-
# __geek = geek
24-
25-
# class MapSubclass(Map):
26-
27-
# # provides new signature for geek() but
28-
# # does not break __init__()
29-
# def geek(self):
30-
# print("In Child class")
31-
32-
# # Driver's code
33-
# obj = MapSubclass()
34-
# obj.geek()
4+
x[2][0] = 1
5+
6+
print(x)
7+
print(x[1] is x[2])

notes/update.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""
2+
Метод update добавляет содержимое одного словаря в другой. x переопределяет y, отсюда {'b': 2, 'c': 11, 'a': 1}
3+
"""
4+
5+
x = {'a':1, 'b': 2}
6+
y = {'b':10, 'c': 11}
7+
8+
y.update(x)
9+
print(y)

0 commit comments

Comments
 (0)