class Player:
def __init__(self, name):
self.name = name
def __hash__(self):
return hash(self.name)
def __eq__(self, other):
return self.name == other.name
p1 = Player("loneymist")
p2 = Player("loneymist")
games = {p1: "CS 1.6"}
games[p2] = "Beat Saber"
print(len(games), games[p1])
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
funcs = []
for i in range(3):
funcs.append(lambda x=i: x)
print([f() for f in funcs])
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
music = ["ATEEZ", "21 pilots"]
music[1:1] = music
print(len(music), music[1])
#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
class A:
def ping(self): print("A", end=" ")
class B(A):
def ping(self): print("B", end=" "); super().ping()
class C(A):
def ping(self): print("C", end=" "); super().ping()
class D(B, C):
def ping(self): print("D", end=" "); super().ping()
D().ping()
#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
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
Please open Telegram to view this post
VIEW IN TELEGRAM
try:
raise SystemExit()
except Exception:
print("A")
except BaseException:
print("B")
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
class MockObject:
def __new__(cls):
return 42
def __init__(self):
print("Init")
obj = MockObject()
print(obj)
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
try:
raise KeyError()
except KeyError:
print("K", end="")
else:
print("E", end="")
finally:
print("F", end="")
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
class Counter:
count = 0
def __init__(self):
self.count += 1
c = Counter()
print(Counter.count, c.count)
#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