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:
def __getitem__(self, i):
return i
a = A()
a.__getitem__ = lambda i: i**2

print(a[4])
What will this code do?
from functools import reduce
print(reduce(lambda acc, x: x * acc, [1,2,3,4], 1))
👍1
What will this code do?
class A:
x = 'hello'
def __getitem__(self, i):
return getattr(self.x, '__getitem__')(i) * 2
def __getattr__(self, attr):
return getattr(self.x, attr)
a = A()
print(a[0] + a.upper()[1:])
What will this code do?
f = type
print(f(f(f(f(f(None))))) is f )
What will this code do?
"hello, Макс!".encode('ascii', errors='replace')
What will this code do?
"hello, Макс!".encode('ascii', errors='ignore')
What will this code do?
class С: pass 
c = С()
a = type(c) == c.__class__
b = type(type(c)) is c.__class__.__class__
print(a, b)
What will this code do?
"hello, Макс!".encode('ascii', errors='strict')
What will this code do?
(type(type) is type(object)) - isinstance(type, object)
👍1
What will this code do?
isinstance(type, object) + isinstance(object, type) + (type is object)
👍1