Ask Question

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.

+5
Answers (1)
  1. 4 June, 17:07
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers