What will this code do?
a = 1 * 1
b = 1 / 1
print(a == 1, b == 1, a is 1, b is 1)
How to print python philosophy?
Anonymous Quiz
37%
import this
12%
import philosophy
20%
print(__philosophy__)
6%
print(__pypy__)
4%
print()
8%
exec('__ph__')
14%
See solution
π€―2
What will this code do?
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))
π1
Choose your answer
Anonymous Quiz
22%
5 5
5%
23 5
38%
5 23
14%
23 23
8%
NameError
3%
RecursionError
11%
See solution
π1
What will this code do?
S = 'abcdef'
print(S.islower() + S.lower().isalpha() + S.isupper())
Choose your answer
Anonymous Quiz
2%
0
2%
1
41%
2
0%
3
12%
6
2%
True
10%
False
20%
TypeError
10%
See solution
π1
What will this code do?
class A:
def __getitem__(self, i):
return i
a = A()
a.__getitem__ = lambda i: i**2
print(a[4])
Choose your answer
Anonymous Quiz
9%
4
9%
8
62%
16
2%
None
17%
IndexError
0%
TypeError
2%
See solution
π1
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:])
Choose your answer
Anonymous Quiz
11%
HELLO
29%
hELLO
4%
hhello
36%
hhELLO
7%
HHELLO
7%
IndexError
7%
See solution
π1
What will this code do?
"hello, ΠΠ°ΠΊΡ!".encode('ascii', errors='replace')Choose your answer
Anonymous Quiz
19%
b'hello, !'
21%
b'hello, ****!'
12%
b'hello, ????!'
14%
b'hello, ΠΠ°ΠΊΡ!'
19%
UnicodeEncodeError
14%
See solution
What will this code do?
"hello, ΠΠ°ΠΊΡ!".encode('ascii', errors='ignore')Choose your answer
Anonymous Quiz
26%
b'hello, !'
12%
b'hello, ****!'
28%
b'hello, ΠΠ°ΠΊΡ!'
18%
b'hello, ????!'
6%
UnicodeEncodeError
10%
See solution