Kickstart 2020 with new opportunities! - hours only!Up to 80% off on all courses and bundles.-Close
Quick recap
7. The join() function
Indexing and slicing


Another interesting technique is to use join():

visited_countries = ['Norway', 'Sweden', 'Denmark', 'Germany', 'France']
separator = ', '
print('I have visited the following countries: ' + separator.join(visited_countries))

The code above will show:

I have visited the following countries: Norway, Sweden, Denmark, Germany, France


creates a string that contains all the elements of visited_countries separated by the separator. Note that there is no separator after the last element in the list.


Join all path parts in the template with backslash signs (\) and print the entire string.

Remember—to access a backslash sign in Python, you need to write: '\\'

Stuck? Here's a hint!

Use '\\'.join(path_parts).