0

for example, if the string is "Nikki",

then how can I split it into "N", "i", "k", "k", "i"

help pls

1
  • [i for i in 'Nikki'] also works! Check out Python documents about str. Commented Aug 19, 2020 at 13:20

1 Answer 1

7

You can just construct a list using the string

>>> list('Nikki')
['N', 'i', 'k', 'k', 'i']

Although for what it's worth, a list of chr is functionally equivalent to just iterating directly through the str itself. In other words

for letter in 'Nikki':

will work, as will anything relying on a sequence type.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.