mik*_*ike 1 python logical-operators
我尝试在网上搜索这个答案,但我没有找到任何运气.我想知道python是否支持if语句的其他语言中的逻辑非运算符(通常是'!')或任何控制语句.例如,我希望实现此功能.
if !(re.search('[0-9]', userInputVariable):
fix error and report to user
...Proceed with rest of code...
Run Code Online (Sandbox Code Playgroud)
基本上如果用户没有输入数字,我将其更正为默认值并继续使用脚本
谢谢!
你正在寻找not运营商.
但这不是你检查数字的方式.
try:
int(userInputVariable)
except ValueError:
print "Not a number"
Run Code Online (Sandbox Code Playgroud)
...
if not userInputVariable.isdigit():
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3002 次 |
| 最近记录: |