Ask Question
5 August, 08:41

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.

+2
Answers (1)
  1. 5 August, 11:17
    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?
Get 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 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