So say I have a list named myList
and it looks something like this :
myList = ["a", "b", "c"]
How would you print it to the screen so it prints :
abc
(yes, no space inbetween)
If I use print(myList)
It prints the following:
['a', 'b', 'c']
Help would be much appreciated.
With Python 3, you can pass a separator to print
. *
in front of myList
causes myList
to be unpacked into items:
>>> print(*myList, sep='')
abc
Use str.join()
:
''.join(myList)
Example:
>>> myList = ["a", "b", "c"]
>>> print(''.join(myList))
abc
This joins every item listed separated by the string given.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With