python - python3中的split()没有按预期返回值(拆分整个字符串字符而不是空格)
问题描述
size = int(input())
#a = [0 for x in range(size)]
a = input()
b=[]
a.split()
print (a[0])
for x in a:
if is_number(x):
b.append(int(x))
print (b)
输入:4
12 8 4 0
输出:1
[1, 2, 8, 4, 0]
期待:12
[12、8、4、0]
我在这里做错了什么?注意:a.split(" ")
也不工作
解决方案
split 不会就地改变字符串,它会返回。所以,只需执行以下操作
a = a.split()
推荐阅读
- c# - Visual Studio Publishing 在主开发系统中抛出 System.AggregateException 而没有详细信息
- reactjs - React js路由器在部署时无法通过url正确路由到页面
- python - Tkinter 在更新时保留 Text 中的滚动
- graph - 在有一些约束的有向图中找到循环的算法
- c++ - 将字符附加到字符串
- xml - “ax22”在 XML 中指的是什么?
- python - 2 个列表上的 zip 函数删除值
- c++ - 犰狳 fft2 的线程问题
- r - 按每行中的括号标题拆分和重新排列列
- swift - 在 RealityKit 场景上应用着色器