Use the split method to split a string into substrings.
Combine objects in a list into a string using join method.
split
A string in Python can be broken into substrings given a delimiter. A delimiter is also referred to as a separator. The split method, when applied to a string, splits the string into substrings by using the given argument as a delimiter. Ex: "1-2".split('-') returns a list of substrings ["1", "2"]. When no arguments are given to the split method, blank space characters are used as delimiters. Ex: "1\t2\n3 4".split returns ["1", "2", "3", "4"].
join
The join method is the inverse of the split method: a list of string values are concatenated together to form one output string. When joining string elements in the list, the delimiter is added in-between elements. Ex: ','.join(["this", "is", "great"]) returns "this,is,great".
Adapted from Introduction to Python Programming by OpenStax (openstax.org), licensed under CC BY-NC-SA 4.0. Changes were made. License: CC-BY-NC-SA-4.0.
These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or ADA Title II. Every page is built against an automated accessibility gate, and the published editions will meet ADA Title II requirements when they release in late September 2026. If something is unusable, please tell us.