Python 知识点杂记

输入空格分隔的数组

  1. 输入以空格分隔的数组时,可使用字符串的split函数按空格分隔,例如dir=input().split(' '),得到了数组dir
  2. 但是该数组是以字符串形式存储的,所以此时,我们可以使用map函数,例:dir=map(int,input().split(' '))  来获得一个int数组。
  3. 或者,如果需要使用数量已知的变量去存储,可以直接赋值 例: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:缩进错误

发布了42 篇原创文章 · 获赞 16 · 访问量 3410

猜你喜欢

转载自blog.csdn.net/qq_41542638/article/details/96010961
今日推荐