【问题标题】:How can I change the behavior of array printing in Python? [duplicate]如何更改 Python 中数组打印的行为? [复制]
【发布时间】:2014-04-20 03:11:01
【问题描述】:

当我打印一个数组时:

 pi = [3,1,4,1,5,9,2,6,5]
 print pi

正常打印:

 [3, 1, 4, 1, 5, 9, 2, 6, 5]

我想知道我是否可以像这样打印:

 314159265

如果有怎么办?

【问题讨论】:

  • 感谢指正!

标签: python list


【解决方案1】:

你可以使用str.join:

>>> pi = [3,1,4,1,5,9,2,6,5]
>>> print ''.join(map(str, pi))
314159265

print函数:

>>> from __future__ import print_function  #not required in Python 3
>>> print(*pi, sep='')
314159265

【讨论】:

    猜你喜欢
    • 2021-07-14
    • 2011-08-18
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 2016-02-25
    • 1970-01-01
    • 2019-12-06
    • 2013-02-03
    相关资源
    最近更新 更多