Ask Question
22 June, 02:54

Write a statement that creates a single string from an existing list of strings called "states" by inserting the string ' | ' between every pair of strings in the list. The resulting string should be put into a variable called result_string.

+1
Answers (1)
  1. 22 June, 05:55
    0
    Following are the program in the Python Programming Language.

    #set and initialize list type variable

    states=["Delhi", "UP", "MP", "Goa"]

    #convert list into string and separated by (|)

    result_string=" | ". join (states)

    #print the value of the string

    print (result_string)

    Output:

    Delhi | UP | MP | Goa

    Explanation:

    The description of the program that is in the Python Programming Language.

    Here, we set a list data type variable i. e.,"states" and initialize the list of states in it. Then, set a string data type variable i. e.,"result_string" and convert the list variable "states" into the string and separated by the vertical bar (|). Finally, print the value of the string variable "result_string".
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a statement that creates a single string from an existing list of strings called "states" by inserting the string ' | ' between every ...” 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