Ask Question
23 November, 06:22

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.

+2
Answers (1)
  1. 23 November, 07:19
    0
    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']

    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".
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Currently there is a string called str1. Write code to create a list called chars which should contain the characters from str1. Each ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers