Python3常用小技巧

一.输入输出:

1.多组字符串

import sys
try :
    while True:
        str = sys.stdin.readline().strip('\n')
        print(str)
except :
    pass

 strip()括号里面填的是终止符号(终止符不会被读进字符串)

    

2.多组数字

(1)每组数字量已知

import sys
try :
    while True:
        a,b,c=map(int,input().split())
        print(a,b,c)
except :
    pass

(2)每组数字量未知

import sys
try :
    while True:
        list=[int(x) for x in input().split()]
        print(list)
except :
    pass

   

        或者这样:

import sys
try :
    while True:
        op=map(int,input().split())
        for i in op:
                print(i)
except :
    pass

  

                                

发布了153 篇原创文章 · 获赞 46 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/qq_40922859/article/details/89062237