данных иммутабельные типы - skydns...compile-time constant objects...
TRANSCRIPT
![Page 1: данных иммутабельные типы - SkyDNS...compile-time constant Objects optimization 14 Mutable? Create new object Yes Object type? value in [-5...256]? result of](https://reader034.vdocuments.us/reader034/viewer/2022042408/5f23860c50a1a91a656a134a/html5/thumbnails/1.jpg)
Мутабельные и иммутабельные типы данныхИван Феофанов
apiqa.io
![Page 2: данных иммутабельные типы - SkyDNS...compile-time constant Objects optimization 14 Mutable? Create new object Yes Object type? value in [-5...256]? result of](https://reader034.vdocuments.us/reader034/viewer/2022042408/5f23860c50a1a91a656a134a/html5/thumbnails/2.jpg)
02
5
![Page 3: данных иммутабельные типы - SkyDNS...compile-time constant Objects optimization 14 Mutable? Create new object Yes Object type? value in [-5...256]? result of](https://reader034.vdocuments.us/reader034/viewer/2022042408/5f23860c50a1a91a656a134a/html5/thumbnails/3.jpg)
03
2
![Page 4: данных иммутабельные типы - SkyDNS...compile-time constant Objects optimization 14 Mutable? Create new object Yes Object type? value in [-5...256]? result of](https://reader034.vdocuments.us/reader034/viewer/2022042408/5f23860c50a1a91a656a134a/html5/thumbnails/4.jpg)
04
1
![Page 5: данных иммутабельные типы - SkyDNS...compile-time constant Objects optimization 14 Mutable? Create new object Yes Object type? value in [-5...256]? result of](https://reader034.vdocuments.us/reader034/viewer/2022042408/5f23860c50a1a91a656a134a/html5/thumbnails/5.jpg)
05
Immutable Mutable
int, float, complex list, set
tuple, frozenset dict
bytes bytearray
str
bool
Python data types
![Page 6: данных иммутабельные типы - SkyDNS...compile-time constant Objects optimization 14 Mutable? Create new object Yes Object type? value in [-5...256]? result of](https://reader034.vdocuments.us/reader034/viewer/2022042408/5f23860c50a1a91a656a134a/html5/thumbnails/6.jpg)
Immutable
a = 5
a 5
a += 2
a 7
id = 11197536
id = 11197568
b = a
b
06
![Page 7: данных иммутабельные типы - SkyDNS...compile-time constant Objects optimization 14 Mutable? Create new object Yes Object type? value in [-5...256]? result of](https://reader034.vdocuments.us/reader034/viewer/2022042408/5f23860c50a1a91a656a134a/html5/thumbnails/7.jpg)
WAT?
07
![Page 8: данных иммутабельные типы - SkyDNS...compile-time constant Objects optimization 14 Mutable? Create new object Yes Object type? value in [-5...256]? result of](https://reader034.vdocuments.us/reader034/viewer/2022042408/5f23860c50a1a91a656a134a/html5/thumbnails/8.jpg)
Mutable
a = [5, 10, 15]
a [5, 10, 15]
b = a
bid = 139872397262408
a += [20]
[5, 10, 15, 20]
08
![Page 9: данных иммутабельные типы - SkyDNS...compile-time constant Objects optimization 14 Mutable? Create new object Yes Object type? value in [-5...256]? result of](https://reader034.vdocuments.us/reader034/viewer/2022042408/5f23860c50a1a91a656a134a/html5/thumbnails/9.jpg)
Pitfalls
09
● default mutable arguments● side-effects
![Page 10: данных иммутабельные типы - SkyDNS...compile-time constant Objects optimization 14 Mutable? Create new object Yes Object type? value in [-5...256]? result of](https://reader034.vdocuments.us/reader034/viewer/2022042408/5f23860c50a1a91a656a134a/html5/thumbnails/10.jpg)
Default mutable argument
10
![Page 11: данных иммутабельные типы - SkyDNS...compile-time constant Objects optimization 14 Mutable? Create new object Yes Object type? value in [-5...256]? result of](https://reader034.vdocuments.us/reader034/viewer/2022042408/5f23860c50a1a91a656a134a/html5/thumbnails/11.jpg)
Default mutable argument: solution
11
![Page 12: данных иммутабельные типы - SkyDNS...compile-time constant Objects optimization 14 Mutable? Create new object Yes Object type? value in [-5...256]? result of](https://reader034.vdocuments.us/reader034/viewer/2022042408/5f23860c50a1a91a656a134a/html5/thumbnails/12.jpg)
PEP 505 -- None-aware operators (??=)
12
![Page 13: данных иммутабельные типы - SkyDNS...compile-time constant Objects optimization 14 Mutable? Create new object Yes Object type? value in [-5...256]? result of](https://reader034.vdocuments.us/reader034/viewer/2022042408/5f23860c50a1a91a656a134a/html5/thumbnails/13.jpg)
Side-effect
13
![Page 14: данных иммутабельные типы - SkyDNS...compile-time constant Objects optimization 14 Mutable? Create new object Yes Object type? value in [-5...256]? result of](https://reader034.vdocuments.us/reader034/viewer/2022042408/5f23860c50a1a91a656a134a/html5/thumbnails/14.jpg)
compile-time constant
Objects optimization
14
Mutable?
Create new object
Yes
Object type?
value in [-5...256]?
result of constant folding
int
stringNo
No
Refer to existing object
Yes
Yes
object length > 20?No
Yes
No
Yes
contains only ASCII letters, digits or underscores
No No
Yes
![Page 16: данных иммутабельные типы - SkyDNS...compile-time constant Objects optimization 14 Mutable? Create new object Yes Object type? value in [-5...256]? result of](https://reader034.vdocuments.us/reader034/viewer/2022042408/5f23860c50a1a91a656a134a/html5/thumbnails/16.jpg)
bonus
+=