Ask Question
17 December, 01:24

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.

+5
Answers (1)
  1. 17 December, 01:39
    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 & 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