How split works in Python

Given a string, write a Python program to split the characters from the given string into a list.
 

Examples:  

Input: geeks Output: ['g', 'e', ​​'e', ​​'k', 's'] Input: Word Output: ['W', 'o', 'r', 'd']

  
Code # 1: Using List Comprehension
This approach uses list comprehension to convert each character into a list. Using the following syntax you can split the characters of a string into a list.
 

Python3

 
Output: ['g', 'e', ​​'e', ​​'k', 's']

 

  
Code # 2: Typecasting to list
Python provides direct typecasting of string into list using list ().
 



Python3

 
Output: ['g', 'e', ​​'e', ​​'k', 's']

 

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your data structures concepts with the Python DS Course. And to begin with your machine learning journey, join the Machine Learning - Basic Level Course

My Personal Notesarrow_drop_up