8.13. Split Method
Completion requirements
View
Go through the activity to the end
Receive a grade
Receive a passing grade
Attempt: 1
Reading: Split Method
In this section, we discuss the split() method in Python, which is used to split a string into a list based on specified separators.
- Parameters of the split() Method:
- Separator: This parameter defines the character that will be used to separate the string. The default separator is a space (
" "). - maxsplit: This optional parameter specifies the maximum number of splits to perform. The default value is
-1, which means all occurrences will be counted.
- Separator: This parameter defines the character that will be used to separate the string. The default separator is a space (
Examples:
-
Using Default Separator (Space)
- Input:
"International Burch University" - Output:
["International", "Burch", "University"]
- Input:
-
Using a Custom Separator (Question Mark)
- Input:
"What is your name? Where do you live?" - Output:
["What is your name", " Where do you live?"]
- Input:
-
Using a Custom Separator (Minus Sign)
- Input:
"Python-is-fun" - Output:
["Python", "is", "fun"]
- Input: