TGViewer
Channel Public Channel
Python Tasks & ML | Задачи по питону и машинному обучению

Python Tasks & ML | Задачи по питону и машинному обучению

@python_tasks

Algorithms, functions, classes, regular expressions, iterators, generators, OOP, exceptions, NumPy, pandas, scikit-learn
https://telega.in/c/python_tasks

Questions — @dina_ladnyuk
Subscribers
8.5K
Photos
30
Videos
1
Links
41

Showing posts older than #2242 · Back to latest

Older Posts 20 shown
Post #2241 1.47K
Что выведет код?
x = 1
def f1():
return x
def f2():
global x
x = 2
return x
def f3():
global x
return x
print(f1(), f2(), f3(), f1())
Post #2239 1.39K
Дан код
try:
my_x = 1
raise Exception('исключение') #1
except Exception as my_err:
print(my_err) #2
my_y = 2
print(my_x) #3
print(my_y) #4
print(my_err) #5
Post #2237 1.33K
Что выведет код?
def f():
x = 1
y = 1
def g():
nonlocal x
x, y = 2, 2
g()
print(x, y)

f()
Post #2235 1.24K
Что выведет код?
def f(n):
return 0 if n == 0 else 2**n + f(n-1)
print(f(3))
Post #2233 1.32K
Что выведет код?
def intersect(*seqs):
if len(seqs) > 2:
return intersect(seqs[0], intersect(*seqs[1:]))
seq1, seq2 = seqs[0], seqs[1]
res = []
for x in seq1:
if x in seq2:
res.append(x)
return res

x = intersect([1, 2, "a", "b"], (1, 4, "b"), {1, "b", "c"})
print(x)
Post #2231 1.39K
Что выведет код?
class A:
__x = 1
def f(self):
return "f from A"

def g(self):
return "g from A"

class B:
__x = 2
def f(self):
return "f from B"

def g(self):
return "g from B"

class C(A, B):
f = B.f

c = C()
print(c.f(), c.g(), c._A__x, c._B__x)
  • 👍 2
Post #2229 1.25K
Что выведет код?
class MyList(list):
def __getitem__(self, index):
if type(index) is slice:
index = slice(index.start - 1, index.stop - 1, index.step)
elif type(index) is int:
index -= 1
return list.__getitem__(self, index)

l = MyList(["one", "two", "three", "four", "five", "six"])

print(l[1], l[-1], l[0], l[2:4])
Post #2227 1.35K
Что выведет код?
a = 1 * 1
b = 1 / 1
print(a == 1, b == 1, a is 1, b is 1)
  • 👍 1
Post #2225 1.25K
Что выведет код?
class A:
def __init__(self, x):
self.x = x
def __getattribute__(self, name):
if name == '__add__':
self.x *= 10
return object.__getattribute__(self, name)
def __add__(self, other):
return self.x + other.x

a1 = A(2)
a2 = A(3)
print(a1 + a2, a1.__add__(a2))
  • 👍 2
Post #2224 1.44K
  • 🤔 3
  • 😱 1
Post #2223 1.25K
Что выведет код?
class A:
def __getitem__(self, i):
return i
a = A()
a.__getitem__ = lambda i: i**2

print(a[4])
Older posts →
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →