How to split string into char array in Python

4 Answers

0 votes
s = 'python'

lst = list(s)

print(lst)



'''
run:

['p', 'y', 't', 'h', 'o', 'n']

'''

 



answered Apr 14, 2021 by avibootz
0 votes
s = 'python'

lst = []

lst.extend(s)

print(lst)



'''
run:

['p', 'y', 't', 'h', 'o', 'n']

'''

 



answered Apr 14, 2021 by avibootz
0 votes
s = 'python'

lst = [*s]

print(lst)



'''
run:

['p', 'y', 't', 'h', 'o', 'n']

'''

 



answered Apr 14, 2021 by avibootz
0 votes
s = 'python'

lst = [ch for ch in s]

print(lst)



'''
run:

['p', 'y', 't', 'h', 'o', 'n']

'''

 



answered Apr 14, 2021 by avibootz

Related questions

1 answer 126 views
2 answers 164 views
2 answers 135 views
2 answers 217 views
1 answer 186 views
2 answers 250 views
...