我正在创建一个检查输入并在输入格式不正确时退出的函数。但是,我收到一个错误,提示 sys.exit() 是“无效语法”。任何帮助将非常感激!
import re
import sys
def my_program(x):
# takes input in form '#d#'
if re.match('\d\w\d', x ) is False:
print('Format of input must be '#d#')
sys.exit()
Run Code Online (Sandbox Code Playgroud)
问题不在于sys.exit(),而在于它上面的那一行。
你有一个额外的报价。
print('Format of input must be #d#')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6767 次 |
| 最近记录: |