Ask Question
31 May, 08:04

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.

+1
Answers (1)
  1. 31 May, 10:30
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers