How to change the print behavior of arrays in Python?

When I print an array:

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

It prints as usual:

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

I was wondering if it is possible to print as:

 314159265

If so, how?

+4
source share
1 answer

You can use str.join:

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

Or print:

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

Source: https://habr.com/ru/post/1531823/


All Articles