作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试接受意见。但这不是正确的语法。
a, b, c = (int(x) for x in raw_input().strip(' '))
我的想法是从一行中获取多个值,其中整数由空格分隔。我该怎么做?
最佳答案
你们很亲密。它是split
而不是strip
:
a, b, c = (int(x) for x in raw_input().split())
这将恰好需要 3 个整数,不多也不少。如果你想将任意数量的数据放入一个元组中,试试这个:
tup = tuple(int(x) for x in raw_input().split())
关于python - 如何在 python 中使用 raw_input 将元组作为输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48472265/
我是一名优秀的程序员,十分优秀!