Python & ML tasks
415 subscribers
2 photos
3 links
Python, functions, classes, iterators, generators, numpy, pandas, scikit-learn, TensorFlow
for advertising: @dina_ladnyuk

For advertising and donations in USD:
SWIFTBIC BUKBGB22
IBAN GB40 BUKB 2047 3453 2396 99
Mrs Dina Ladnyuk
Download Telegram
What will this code do?
class A:
count = 0
def __init__(self):
A.count = A.count + 1
def get(self):
return A.count
x, y, z = A(), A(), A()
print(x.get(), A().__class__.get(A()), z.__class__.get(y))
What will this code do?
class A:
count = 0
def __init__(self):
A.count += 1
def print_count():
print(A.count)
print_count = staticmethod(print_count)

class B(A): pass

x, y, z = B(), A(), B()
B.print_count()
What will this code do?
class A:
count = 0
def __init__(self):
A.count += 1
def print_count():
print(A.count)
print_count = staticmethod(print_count)

class B(A): pass

x, y, z = B(), A(), B()
B.print_count()
What will this code do?
class A:
count = 0
def __init__(self):
print(self.count, self.__class__, self.__class__.count)
self.__class__.count += 1

class B(A):
pass

class C(A):
pass

x, y, z = B(), A(), C()
print(A.count, B.count, C.count)
What will this code do?
class A:
count = 0
@classmethod
def inc(cls):
cls.count += 1
def __init__ (self):
self.inc()

class B(A):
count = 0
def __init__(self):
A.__init__(self)

class C(A):
count = 0

x = A()
y1, y2 = B(), B()
z1, z2, z3 = C(), C(), C()
print(x.count, y1.count, z1.count)
What will this code do?
import random
random.random() < random.randint(1, 10)
What will this code do?
(0 or 8 != 11 or 0) + (0 and 8 != 11 and 0)
What will this code do?
class counter:
def __init__(self, func):
self.calls = 0
self.func = func

def __call__(self, *args):
self.calls += 1
return self.func(*args), self.calls

@counter
def square(a):
return a ** 2

print(square(2)[0] + square(3)[0] + square(4)[1])
Choose your answer
Anonymous Quiz
8%
3
8%
6
17%
15
33%
16
25%
29
8%
See solution
What will this code do?
5 >> 1 << 1
Choose your answer
Anonymous Quiz
20%
0
35%
1
20%
4
15%
5
0%
511
10%
See solution
What will this code do?
class A: pass
class B:
def __init__(self):
x = super()
print(x is A, x is B)

b = B()
What will this code do?
def f(*, name):
print(len(name), end=" ")

try:
f(name="vasya")
f("sergey")
except:
f(name="oleg")