如何在python中将单个数字转换为单个项目列表 [英] How to convert a single number into a single item list in python
本文介绍了如何在python中将单个数字转换为单个项目列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的解决方案:
>>> i = 2
>>> list1 = []
>>> list1.append(i)
>>> list1
[2]
是否有更优雅的解决方案?
Is there a more elegant solution?
推荐答案
这只是一个特例:
list1 = []
您可以将列表内容放在括号中。例如:
You can put the lists contents between the brackets. For example:
list1 = [i]
这篇关于如何在python中将单个数字转换为单个项目列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文