I want to convert my list of integers into a string. Here is how I create the list of integers:
new = [0] * 6 for i in range(6): new[i] = random.randint(0,10)
Like this:
new == [1,2,3,4,5,6] output == '123456'
To convert a list to a string, use Python List Comprehension and the join() function. The list comprehension will traverse the elements one by one, and the join() method will concatenate the list's elements into a new string and return it as output.
In Python an integer can be converted into a string using the built-in str() function. The str() function takes in any python data type and converts it into a string.
With Convert a list of characters into a string you can just do
''.join(map(str,new))
There's definitely a slicker way to do this, but here's a very straight forward way:
mystring = "" for digit in new: mystring += str(digit)
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