Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    PyPython

    Getting started

    • Your first Python program
    • Variables and types
    • Numbers and operators
    • Type conversion and input

    Strings

    • Strings and f-strings
    • String indexing and slicing
    • Cleaning and splitting strings

    Control flow

    • Conditions: if, elif and else
    • Loops: for and while
    • Loop control and nesting

    Functions

    • Functions with def
    • Parameters and scope

    Collections

    • Lists
    • Dictionaries
    • Tuples and sets
    • Comprehensions, enumerate and zip

    Errors, files and libraries

    • Handling exceptions
    • Modules and the standard library
    • Reading and writing files
    • Exchanging data with JSON

    Objects and lazy iteration

    • Classes and objects
    • Inheritance and composition
    • Iterators and generators

    Testing and project

    • Testing and project setup
    • Project: a grade report
    Python

    Strings · Lesson 7 of 25

    Cleaning and splitting strings

    strip, split, join, searching and replacement.

    8 minutes2 games

    Incoming text may contain surrounding whitespace or mixed case. strip() trims the ends; lower() normalizes case. split() returns a list of parts, and join() combines strings with your chosen separator.

    Raw text

    Trim and normalize

    Split into parts

    Join the result

    Python
    raw = "  Python,HTML,CSS  "
    clean = raw.strip().lower()
    parts = clean.split(",")
    print(parts)
    print(" | ".join(parts))
    print("python" in clean)
    print(clean.replace("html", "javascript"))

    Important

    strip() only trims the ends, not spaces in the middle. join requires string elements, not numbers.

    Interview question

    How do split() and split(" ") differ?

    What's the output?

    print("  sea code  ".strip().upper())

    What will this code print?

    Exercise

    Trim and lowercase the name, then print mona.

    Expected output: mona

    Python
    name = "  MONA  "
    

    Learn more from

    • Python documentationdocs.python.org
    • Real Python: further readingrealpython.com

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousString indexing and slicingNextConditions: if, elif and else
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.