Заметки Питониста
14.8K subscribers
3.35K photos
17 videos
1.8K links
Все что связано с Python, уже в наших заметках.

Ссылка: @Portal_v_IT

Сотрудничество: @oleginc
Download Telegram
gen = (x for x in range(5))
print(2 in gen, 2 in gen)


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

#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
Варианты ответа:
Anonymous Quiz
20%
True True
68%
True False
11%
False False
gen = (x for x in range(3))
print(list(gen), list(gen))


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

#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
Варианты ответа:
Anonymous Quiz
30%
[0, 1, 2] [0, 1, 2]
66%
[0, 1, 2] []
5%
TypeError
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
Варианты ответа:
Anonymous Quiz
54%
42
28%
Init 42
18%
TypeError
class Point:
__slots__ = ['x', 'y']

p = Point()
p.x = 1
p.z = 2
print(p.x)


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

#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
Варианты ответа:
Anonymous Quiz
33%
1
28%
None
40%
AttributeError
def add_item(val, target=[]):
target.append(val)
return target

print(add_item(1), add_item(2))


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

#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
👍1
Варианты ответа:
Anonymous Quiz
48%
[1] [1, 2]
26%
[1] [2]
26%
[1, 2] [1, 2]
colors = ['red', 'green', 'blue']
colors.insert(1, colors.pop())
colors.reverse()
print(colors[0])


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

#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
Варианты ответа:
Anonymous Quiz
36%
red
42%
green
23%
blue
d = {'a': 1, 'b': 2}
try:
for k in d:
del d[k]
print("Done")
except RuntimeError:
print("Error")


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

#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
Варианты ответа:
Anonymous Quiz
33%
Done
56%
Error
12%
KeyError
from collections import defaultdict

class Tree(defaultdict):
def __init__(self):
super().__init__(Tree)

t = Tree()
t['a']['b']['c'] = 10
t['a']['b']['d'] = 20
t['a']['e'] = 5

def count_leaves(d):
total = 0
for v in d.values():
if isinstance(v, dict):
total += count_leaves(v)
else:
total += v
return total

print(count_leaves(t))


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

#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
Варианты ответа:
Anonymous Quiz
41%
30
56%
35
3%
25
👩‍💻 Хватит учить только синтаксис, начинай делать реальные проекты!

Python Ready — авторский канал, где Python перестаёт быть только теорией и становится рабочим инструментом. Мини-проекты, боты, советы, разборы задач, гайды и шпаргалки для каждого программиста.

🔥 Советую подписаться: @python_ready
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM