I will write how to make a string into an array in Python, and how to make an array into a string. I look forward to working with you.
When making a character string an array.
s = 'AIUEO'
print(list(s))
print([i for i in s])
#['Ah', 'I', 'U', 'e', 'O']And output
When making an array a character string.
print(''.join(['Ah', 'I', 'U', 'e', 'O']))
print(*['Ah', 'I', 'U', 'e', 'O'], sep='')
#Aiueo and output
When making an array of numbers into a character string.
n = [1, 2, 3, 4, 5]
print(''.join([str(i) for i in n]))
print(*[str(i) for i in n], sep='')
#12345 and output
#If join is int, an error will occur, so I am converting to str
that's all. Thank you very much.
Recommended Posts