python 中如何实现一行输入多个值 ?

来源:互联网 发布:做淘宝电脑配置 编辑:程序博客网 时间:2024/05/19 14:02

一、

python2的raw_input以及python3的input获取的是整行的字符串。读进来后,字符串的split可以根据分隔符拆解成子串组成的list。对于list内的对象,需要的采取转换,保留字符串的继续保留即可。

一行读入多个字符,并转换成int类型:

a, b, c = map(int, raw_input().split())

如果是py3,自行替换raw_input为input
这时,a,b,c的类型是int



二、只是一行输入多个值

只是一行读入多个字符:

a, b, c = raw_input().split()

这时,a,b,c的类型是str




转载自:https://www.zhihu.com/question/45060860

相关链接:

http://www.jianshu.com/p/61eec6137d41
阅读全文
0 0
原创粉丝点击