c = 3
def add():
c = c + 2
return c
add()
c is not defined in the function's scope, thus:
UnboundLocalError: local variable 'c' referenced before assignment
class A:
def get_balance(self):
return 1
class B:
def get_balance(self):
return 2
class C(A, B):
pass
c = C()
print(c.get_balance())
Keyword: MRO (Method resolution order)
-
set() -> mutable
-
Frozenset -> immutable
No. Because of GIL.
Multiprocessing.
Thanks to GIL, There is no need to write thread-safe programs most of time. No need for locks, semaphores, and thread syncronization primivites.
What happens if multiple threads share the same variable? (E.G: getting an integer value and incrementing it by one) (LUX)
...
...
String/Unicode/Byte compability.
Bytes/string literals
Prefix Python 2 strings that are meant to contain bytes with a b prefix to very clearly delineate what is and is not a Python 3 text > > string (six provides a function to use for Python 2.5 compatibility). This point cannot be stressed enough: make sure you know what all of your string literals in Python 2 are meant to be in Python 3. Any > string literal that should be treated as bytes should have the b prefix. Any string literal that should be Unicode/text in Python 2 ?> should either have the u literal (supported, but ignored, in Python 3.3 and later) or you should have from future import unicode_literals at the top of the file. But the key point is you should know how Python 3 will treat every one one of your string literals and you should mark them as appropriate. There are some differences between byte literals in Python 2 and those in Python 3 thanks to the bytes type just being an alias to str > in Python 2. See the Handle Common “Gotchas” section for what to watch out for.
Check this.
...
-
Python maintains a count of the number of references to each object in memory. If a reference count goes to zero then the associated object is no longer live and the memory allocated to that object can be freed up for something else occasionally things called "reference cycles" happen.
-
The garbage collector periodically looks for these and cleans them up. An example would be if you have two objects o1 and o2 such that o1.x == o2 and o2.x == o1. If o1 and o2 are not referenced by anything else then they shouldn't be live. But each of them has a reference count of 1.
-
Certain heuristics are used to speed up garbage collection. For example, recently created objects are more likely to be dead. As objects are created, the garbage collector assigns them to generations. Each object gets one generation, and younger generations are dealt with first.
Lists are mutable, Tuples are not.
It's a mix depending of the type of the argument.
- https://learntofish.wordpress.com/2012/01/09/call-by-object-reference-call-by-sharing/
- https://medium.com/ey-devel/python-ve-call-by-sharing-d632807ff64c
...
...