def make_counter():
count = 0
def increment():
nonlocal count
count += 1
return count
return increment
c1 = make_counter()
c2 = make_counter()
c1()
print(c1(), c2())
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
class A:
def __new__(cls):
return 42
def __init__(self):
print("Init")
print(A())
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
😱1
val = 10
def update():
global val
val = 20
del val
update()
try:
print(val)
except NameError:
print("NameError")
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
def swap(a, b):
return b, a
x, y = 10, 20
x, y = swap(x, y)
x, y = swap(y, x)
print(x + y)
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM