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.

Examples:

  1. Using Default Separator (Space)

    • Input: "International Burch University"
    • Output: ["International", "Burch", "University"]
  2. Using a Custom Separator (Question Mark)

    • Input: "What is your name? Where do you live?"
    • Output: ["What is your name", " Where do you live?"]
  3. Using a Custom Separator (Minus Sign)

    • Input: "Python-is-fun"
    • Output: ["Python", "is", "fun"]
You have completed 0% of the lesson
0%