Question: Task 1: Joining a list of Strings For this task you 're going to write a function that joins strings from a list. The function

 Task 1: Joining a list of Strings For this task you

're going to write a function that joins strings from a list.

Task 1: Joining a list of Strings For this task you 're going to write a function that joins strings from a list. The function ca join () has one formal parame is like end or sep in the print ) function. You don't have to use it because there's a default value. For the print ) function, e.g., n' (newline) is the default value for end. The formal parameter is a list whose elements are strings. The optional parameter sep has a default value of a single blank space (ie, sep-r. recall that a blank space is a string) join () returns a single string consisting of the concatenati of all the elements in the list, each separated by sep: lled eter and one optional parameter. Recall that an optional parameter : >>> title ['Black', ,Panther'] join (title) Black >>> join (title, Use default value of sep Panther, sepe'') # sep is an empty string sBlackPanther 6 >>> join (title, ,-*-') # sep is 3 characters /Black--Panther' >>> name = [, Instellar') 9 Join (name) 10 , Interstellar, # Make sure it works with a one-element list sep="-*-") >>> join (name , Interstellar # It still works In this code the list title defined in line 1 has two string elements. When this list is passed as the argument of join () in line 2, the return value is a single string with the default value of sep (blank space) separating the elements of the original list. In line 4 we override the default value of sep by setting it to an empty string with the result shown in line 5. In line 6 the join) function is called with the separator-We don't have to use sep- explicitly if we put it in the proper place relative to the function definition. Line 7 shows the resulting string. In line 8 a Kindle 2B....xs MacBook Air

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!