37. Problem to convert a string into a list.

In this program, we will take a user input as a string and convert that string into a list with the help of the below-given steps.

Convert a string into a list:

Steps to solve the program
  1. Take a string as input.
  2. Split the given string using the split function and store it in a variable.
  3. Print the variable to see the output.
				
					#Input string
string = "i am learning python"

#Splitting the string
list1 = string.split(" ")

#Printing output
print(list1)
				
			

Output :

				
					['i', 'am', 'learning', 'python']
				
			

Related Articles

Get all the unique numbers in the list

Replace the last and the first number of the list

Leave a Comment