简体   繁体   English

删除整数列表中项目之间的空格

[英]Removing spaces between items in list of Integers

a=[1, 2, 3, 4]

how to make it如何制作

a=[1,2,3,4]

Split and replace wont work as it is an integer list.拆分和替换不起作用,因为它是一个整数列表。

The spaces are not part of your object which means that you can not remove them.这些空间不是您对象的一部分,这意味着您无法删除它们。 That's just a representation choice.这只是一种代表选择。 eg例如

>>> a=[1,2,3,4] 
>>> a
[1, 2, 3, 4]

But if you want to print your list in string mode you can use str.replace() :但是如果你想以字符串模式打印你的列表,你可以使用str.replace()

>>> str(a).replace(' ','')
'[1,2,3,4]'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM