Examples :
Input: geeks Output: [’g’,’ e’, ’e’ , ’k’,’ s’] Input: Word Output: [’W’,’ o’, ’r’,’ d’]
Code # 1: Using a For Loop
This approach uses a loop to convert each character to a list. Simply enclosing the For loop in square brackets [] will split the characters of the word into a list.
|
Exit:
[’g’,’ e’, ’e’,’ k’, ’s’]
Code # 2: coercion to a list
Python provides direct typing of a string into a list using list ()
.
|
Exit :
[’g’,’ e’, ’e’,’ k’, ’s’ ]