Thursday 23 September 2021

Python: Convert string to list of characters

‘list()’ function can take a string as argument and return list of characters.

 

list_demo_1.py

str = 'Hello World'
print(list(str))

 

Output

['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']

 

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment