python如何一次性输入多行字符串

2020-09-23 16:17:00
六月
来源:
https://www.zhihu.com/tardis/landing/360/ans/560690875
转贴 1771

Python 3 的 input()获取的是整行的字符串。

#方法一: 

a, b, c = map(int, input('请输入3个整数, 用空格分隔:').split())   

print ('\n输入3个整数为:%s %s %s'%(a, b, c))

#方法二:  

a, b, c = input('请输入3个整数, 用空格分隔:').split()  

print( '\n输入3个整数为:%s %s %s'%(a, b, c))

#方法三: 

a, b, c = (int(x) for x in input('请输入3个整数, 用空格分隔:').split()) 

print ('\n输入3个整数为:%s %s %s'%(a, b, c))


参考:https://www.zhihu.com/tardis/landing/360/ans/560690875

发表评论
评论通过审核后显示。