繁体   English   中英

如何打印或加入列表的特定元素(Python)?

[英]How to print or join specific elements of a list (Python)?

list = [8,4,3,2,5]

有没有办法结合两个不使用切片的元素

print ' '.join(list[0:3]) #would print out the numbers in between

如果我只想打印那些特定元素怎么办?

您可以使用Python的字符串格式化程序

>>> arr = [8,4,3,2,5]
>>> print "{0} {3}".format(*arr)
8 2

另外,请不要使用内置函数/类型(例如list命名变量。

暂无
暂无

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

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