Python | Тесты для программистов
15.9K subscribers
3.29K photos
8 videos
1.33K links
Ежедневный чек-ап знаний

Ссылка: @Portal_v_IT

Сотрудничество: @oleginc, @tatiana_inc

Канал на бирже: telega.in/c/pythontest_it

РКН: clck.ru/3KHeRe

#ROLCV
Download Telegram
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
class A:
x = 1
lst = [x for _ in range(3)]

print(A.lst)


💕 Наш уютный чатик

#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
lst = [1, 2, 3, 4]
for i in lst:
lst.remove(i)

print(lst)


💕 Наш уютный чатик

#Python
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
print(issubclass(type, object), issubclass(object, type))


💕 Наш уютный чатик

#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
a = {1, 2, 3}
b = {3, 4, 5}
print(a + b)


💕 Наш уютный чатик

#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
print(isinstance(True, int))


💕 Наш уютный чатик

#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
x = float('inf')
print(x + 1 == x, x - x)


💕 Наш уютный чатик

#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
d = dict.fromkeys(["a", "b"], [])
d["a"].append(1)
print(d["b"])


💕 Наш уютный чатик

#Python
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
print(True << 2, False >> 1)


💕 Наш уютный чатик

#Python
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
x = 1

def calc():
print(x)
x = 2

calc()


💕 Наш уютный чатик

#Python
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
for i in range(3):
pass

print(i)


💕 Наш уютный чатик

#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
print(sum(["a", "b", "c"], ""))


💕 Наш уютный чатик

#Python
Please open Telegram to view this post
VIEW IN TELEGRAM