The parenthesis of Schroedinger | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Resposta
+ 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