+ 1
Empty List and Tuples
Why does the below code returns True for Lists and False for Tuples? def is_it_true (anything): if anything: print ("yes, it's true") else: print ("no, it's false) is_it_true( [[]]) Yes, it's true is_it_true ( (())) No, it's false
3 odpowiedzi
+ 3
When you create tuples with 1 item, you need to put a comma to tell that the parentheses are used to create a tuple, not to affect operation precedence.
(5,) -> (5,)
(5) -> 5
+ 1
def abc(anything):
if anything :
print('true')
else:
print('false')
abc(((),))
returns true