python - 打印列表作为输出

标签 python

我想将 num1 和 num2 转换为列表并打印它,关于如何完成此操作的任何输入?

num1 = 12345
num2 = 34266 73628


print num1
print num2

EXPECTED OUTPUT:-

['12345']
['34266','73628']

最佳答案

我假设 num1num2 都是字符串(否则会出现语法错误)。您可以使用 str.split() :

>>> num1 = '12345'
>>> num2 = '34266 73628'
>>> num1.split()
['12345']
>>> num2.split()
['34266', '73628']

关于python - 打印列表作为输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17159852/

相关文章:

python - 尝试通过Python移动文件但无法移动文件夹

Python Mysql更新执行命令

python - 无法为 "high"x 计算 e^(-x)

python,生成器迭代一个或多个项目

python - Tornado 下一个查询字符串 URL 参数

Python 神奇的 __getattr__() 的 PHP 方法

python - Django - 无法添加中间件

python - 如何在视频上n秒后运行特定代码

python - 从需要登录的页面中抓取数据

Python 嵌套循环 - 无输出