The parenthesis of Schroedinger | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The parenthesis of Schroedinger

Could someone explain this paradox to me: def some_func(): print("Hi!") foo = print() if foo == None: print ("empty1") else: print ("something there1") foo = () if foo == None: print ("empty2") else: print ("something there2") Output : empty1 something there2 The first empty parenthesis was interpreted as a None, but the second was interpreted as something.

16th Dec 2016, 4:16 PM
Yuri Disaró Amado
Yuri Disaró Amado - avatar
1 Answer
+ 2
The first condition occurs because the return of just a print() is None. For the second statement, you are assigning foo to (), which in python declares a tuple. So foo is of tuple type and not None type.
16th Dec 2016, 10:20 PM
akshil
akshil - avatar