+ 2

Is this possible with python?

I'm trying to assign two values to one variable such that if the first value is missing from the provided options, it picks the second one. Something like a = 1 or "__"?

12th Jun 2020, 9:05 AM
Ptar*
Ptar* - avatar
2 odpowiedzi
+ 6
Yes it would work. If the first value is *falsy* the second one would be returned. A use case can be like this : ``` name = input() or "Anonymous" print("Hi",name) ``` Check other falsy values here : https://docs.python.org/2.4/lib/truth.html
12th Jun 2020, 9:16 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 2
Or returns the first value if it evalutes to true, otherwise it returns the second value. The value that are "Falsy" are: -Empty strings, lists, tuples, dictionaries and other empty iterables. -None -0 and other zero numbers(such as 0.0)
12th Jun 2020, 9:56 AM
Mandip Adhikari
Mandip Adhikari - avatar