输入空格分隔的数组
- 输入以空格分隔的数组时,可使用字符串的split函数按空格分隔,例如dir=input().split(' '),得到了数组dir
- 但是该数组是以字符串形式存储的,所以此时,我们可以使用map函数,例:dir=map(int,input().split(' ')) 来获得一个int数组。
- 或者,如果需要使用数量已知的变量去存储,可以直接赋值 例:ch1,ch2,ch3=map(int,input.split(' '),不过此时输入的数字个数必须与左边变量个数一致
Python 怎么设置遇到EOF停止循环
使用try:。。。except: 语句块将input包起来,当遇到EOF异常时,执行except语句块。
例如:
while True:
try:
x1,y1,x2,y2=map(int,input().split())
except:
break
杂记:
Python中没有自增运算符,所以只能使用类似+=1方式
expected an indented block:缩进错误