close

How to split String to Char Array in Python

Hello guys. How are you all? i hope you all fine. In this tutorial we will learn about How to split String to Char Array in Python. By given different methods you can split the character of the string into a list in python. So without wasting your time lets learn about of this.

How to split String to Char Array in Python

  1. Split String to Char Array in Python

    to split String to Char Array in Python just Use for loop. Here for loop is used to split string to Char Array in Python. For loop append each character to the empty list and split it to char. In this method first of all make your string which you want to split then make list in which you want to split your string. And then you can use for loop to split it and you can get the each character appended like in my output. So lets learn this method by given below example: mystr = 'Good morning' mylst = [] for i in mystr: mylst.append(i) print(mylst) Output : ['G', 'o', 'o', 'd', ' ', 'm', 'o', 'r', 'n', 'i', 'n', 'g']

  2. How to split String to Char Array in Python

    to split String to Char Array in Python just Use list(). By using list you can split String to Char Array in Python. In given below example you can see that. you can use your string like this way with list : list(mystr) and it will give you the list of the appended character of your string. Lets learn this method by given below example:
    mystr = 'Good morning' mylst = list(mystr) print(mylst) Output : ['G', 'o', 'o', 'd', ' ', 'm', 'o', 'r', 'n', 'i', 'n', 'g']

Method 1: Use for loop

Here for loop is used to split string to Char Array in Python. For loop append each character to the empty list and split it to char. In this method first of all make your string which you want to split then make list in which you want to split your string. And then you can use for loop to split it and you can get the each character appended like in my output. So lets learn this method by given below example:

mystr = 'Good morning'
mylst = []
for i in mystr:
    mylst.append(i)
print(mylst)

Output :

['G', 'o', 'o', 'd', ' ', 'm', 'o', 'r', 'n', 'i', 'n', 'g']

Method 2: Use list()

By using list you can split String to Char Array in Python. In given below example you can see that. you can use your string like this way with list : list(mystr) and it will give you the list of the appended character of your string. Lets learn this method by given below example:

mystr = 'Good morning'
mylst = list(mystr)
print(mylst)

Output :

['G', 'o', 'o', 'd', ' ', 'm', 'o', 'r', 'n', 'i', 'n', 'g']

Method 3: Use unpack

By using unpack method with the use of* you can split your string into char just like above methods. Lets learn this method. Its very simple and easy. Lets learn this.

mystr = 'Good morning'
print([*mystr])

Output :

['G', 'o', 'o', 'd', ' ', 'm', 'o', 'r', 'n', 'i', 'n', 'g']

Method 4: Use extend()

By using extend() you can extend each character of your string. So lets learn this by given below example:

mylst = []
mystr = 'Good morning'
mylst.extend(mystr)
print(mylst)

Output :

['G', 'o', 'o', 'd', ' ', 'm', 'o', 'r', 'n', 'i', 'n', 'g']

Conlusion

Hope all 6 Method Are Useful For You. Comment Below Which Method You Used To Convert String To Datetime In Python. Thank You.

Also Read

Leave a Comment