① Put each character string in the list as an element (2) Convert the characters in the list as elements one by one into a character string.
python
#① Put each character string in the list as an element
'Hello'
↓
['H', 'e', 'l', 'l', 'o']
#(2) Convert the characters in the list as elements one by one into a character string.
['H', 'e', 'l', 'l', 'o']
↓
'Hello'
program
strs = 'Hello'
print(strs)
print(type(strs))
output
Hello
<class 'str'>
What to do: Just put it in ** list () **
program
strs = 'Hello'
strs_list = list(strs) #← Only here
print(strs_list)
print(type(strs_list))
output
['H', 'e', 'l', 'l', 'o']
<class 'list'>
What to do: Create an empty list and add elements one by one.
program
strs = 'Hello'
strs_list = list(strs)
new_strs = '' #Create an empty list to make a string
for i in range(len(strs_list)):
new_strs += strs_list[i]
print(new_strs)
print(type(new_strs))
output
Hello
<class 'str'>
Recommended Posts