Member-only story
5 Hardest Python Questions!
Confuse your pythoneer friends with these questions
3 min readJul 7, 2022
Link for the Part-2 of this story —
1.) round() function 😵💫
What do you think is the result of the following code:
print(round(9/2))
print(round(7/2))
print(round(3/2))
Answer: 4, 4, 2
Why does print(round(7/2))
prints 4 instead of 3 or why does print(round(9/2))
prints 4 instead of 5?
This is because, in python, the round function implements banker’s rounding, where all the half values are rounded to the closest even number.
2.) Instances! 🥸
Guess the output?
class A:
answer = 9 def __init__(self):
self.answer = 10
self.__add__ = lambda x, y: x.answer + y
def __add__(self, y):
return self.answer - yprint(A() + 4)