2 ms·
This is dangerous because sometimes you have legitimate values that are not truthy. print(player_data['score'] or 'does not exist') This will print "does no
by majewsky 7y ago
This is dangerous because sometimes you have legitimate values that are not truthy.
print(player_data['score'] or 'does not exist')
This will print "does not exist" when the score is zero.
- stefco_ 7y agogp's approach works best when you know that the argument is a list or tuple (something which can be empty). Of course, due to python's lack of typing, you should only use that approach when the function is being used in well-understood contexts.