91.2k views
4 votes
Currently there is a string called str1. Write code to create a list called chars which should contain the characters from str1. Each character in str1 should be its own element in the list chars.

User Jikku Jose
by
7.9k points

1 Answer

2 votes

Answer:

Following are the code in the Python Programming Language.

#set and initialize string type variable

str1 = "I love python"

#convert and initialize the value of string into list

chars=list(str1)

#print the value of the list

print(chars)

Output:

['I', ' ', 'l', 'o', 'v', 'e', ' ', 'p', 'y', 't', 'h', 'o', 'n']

Step-by-step explanation:

The description of the program in the Python Programming Language.

  • Here, we set a string data type variable i.e., "str1".
  • Then, convert the value of string into the list through "list()" built-in function that converts the value into the list and store it into the variable "chars".
  • Finally, we print the value of the variable "chars".
User Ninjin
by
9.2k points