Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 913 Bytes

Lection_2_21_9_2019.md

File metadata and controls

38 lines (26 loc) · 913 Bytes

Лекция 2

  • 21.09.2019

Азы

Синонимы

a = [1, 2, 3] b = a a.append(4) print(b)

Классы

`class MyClass: def init(self, x): self.x = x print(f"MyClass id = {id(self)}")

my_object = MyClass(10)*10 print(f"{my_object.x}")`

Выдаст ошибку:

MyClass id = 18672592 Traceback (most recent call last): File ".\Example_2_classes.py", line 6, in <module> my_object = MyClass(10)*10 TypeError: unsupported operand type(s) for *: 'MyClass' and 'int'

Для правильного копирования нужно использовать deepcopy().

Передача параметров - это call by sharing

del удаляет ссылку на объект в памяти, а не сам объект. Если на объект больше нет ссылок, то GC его удалит.