+ 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 "__"?
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
+ 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)