Python 3:
input = int(input("Enter the inputs : ") or "42")Python 2:
input = int(raw_input("Enter the inputs : ") or "42")它是如何工作的?
如果未输入任何内容,则
input/
raw_input返回空字符串。在Python空字符串
False,
bool("") ->False。运算符or返回第一个真实值,在这种情况下为
"42"。
这不是复杂的输入验证,因为用户可以输入任何内容,例如十个空格符号,然后是
True。



