Python Split String into List of Characters Example
Today our leading topic is python convert string to list of characters. This post will give you simple example of how to convert string to list in python. I explained simply step by step how to split a string in python by character. you can understand a concept of python split string into list of characters.
There are several ways to convert strings into a list of characters in python. we will use split() and strip() functions to convert string into list. so let's see the below examples.
You can use these examples with python3 (Python 3) version.
let's see below a simple example with output:
Example 1:
main.py
myString = "Site ItSolutionStuff.com" # Convert String into List newList = list(myString.strip(" ")) print(newList)
Output:
['S', 'i', 't', 'e', ' ', 'I', 't', 'S', 'o', 'l', 'u', 't', 'i', 'o', 'n', 'S', 't', 'u', 'f', 'f', '.', 'c', 'o', 'm']
Example 2:
main.py
myString = "ItSolutionStuff.com is a best site!" # Convert String into List newList = myString.split(" ") print(newList)
Output:
['ItSolutionStuff.com', 'is', 'a', 'best', 'site!']
Example 3:
main.py
myString = "One,Two,Three,Four,Five" # Convert String into List newList = myString.split(",") print(newList)
Output:
['One', 'Two', 'Three', 'Four', 'Five']
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Remove Duplicate Values from List in Python?
- How to Get Unique Elements from List in Python?
- How to Remove null Values from the List in Python?
- Python Remove Empty String from List Example
- Python Get Second Last Element of List Example
- How to Get the Last Element of a List in Python?
- How to Get First Element of List in Python?
- How to Remove Last Element from List in Python?
- How to Remove First Element from List in Python?
- Python List Remove Element by Value Example
- Python List Remove Element by Index Example
- Python Delete File if Exists Example
- Python Post Request with Basic Authentication Example