Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the behavior of array printing in Python? [duplicate]

Tags:

python

list

When I print an array:

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

It prints like normal:

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

I was wondering if I could print like:

 314159265

If so how?

like image 314
user3420845 Avatar asked Feb 13 '23 12:02

user3420845


1 Answers

You can use str.join:

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

Or print function:

>>> from __future__ import print_function  #not required in Python 3
>>> print(*pi, sep='')
314159265
like image 64
Ashwini Chaudhary Avatar answered Feb 16 '23 03:02

Ashwini Chaudhary