Python Tasks & ML | Задачи по питону и машинному обучению
9.4K subscribers
27 photos
1 file
36 links
Algorithms, functions, classes, regular expressions, iterators, generators, OOP, exceptions, NumPy, pandas, scikit-learn
https://telega.in/c/python_tasks

Questions — @dina_ladnyuk
Download Telegram
Что выведет код?
class A:
def __init__(self, x=0):
self.x = x
def f(self):
print(self.x)
a = A(2020)
f = a.f
print(f.__self__ is a, end=" ")
print(f.__func__ is f, end=" ")
print(f.__func__ is a.f, end=" ")
print(f.__func__ is A.f, end=" ")
Что выведет код?
import numpy as np
print(np.asarray([100, 200, 300]).astype(np.int8))
Что выведет код?
import numpy as np
print(np.uint8(1 - 2))
Что выведет код?
import numpy as np
mat = np.array([[1, 2], [4, 5]])
print(round((mat @ np.linalg.inv(mat)).sum()))
Дан код.
class A:
def __init__(self, x):
self.x = x
def __call__(self):
return self.x
class B:
def __init__(self, x):
self.x = x
def method(self):
return self.x
class C:
def __init__(self, x=3):
self.x = x
def __repr__(self):
return str(self.x)

a = A(1)
b = B(2)
c = C(3)
callables = # ваш код
print([act() for act in callables])

Вывод: [1, 2, 3]
Что выведет код?
import numpy as np
A = np.arange(9).reshape(-1, 3)
print(np.linalg.det(A))
Какой паттерн проектирования используется в данном коде?
class A: pass
class B: pass
def f(cls, *args):
return cls(*args)
a = f(A)
b = f(B)
Что нужно добавить, чтобы вывод был True?
from abc import ABC
class L(ABC): pass
# ваш код
print(issubclass(tuple, L))
Как называется роль, которую в данном коде выполняет класс M для класса B?
class M:
def __str__(self):
return str(self.__dict__)

class A:
def __init__(self):
self.x = 1

class B(A, M):
def __init__(self):
super().__init__()
self.y = 2
b = B()
print(b)