Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON TEXT / CHAPTER 03 / Learn / LESSON 03
Third class. Real text often arrives with extra spaces or as pieces to combine.
strip() removes leading and trailing whitespace. It does not touch spaces in the middle.
split(sep) breaks a string into a list of parts on a separator. For example "a,b,c".split(",") → ["a", "b", "c"].
join is a method on the separator: "-".join(parts) glues list items with "-" between them. The order is separator.join(list), not the other way around.
Mini example:
raw = " a,b "
clean = raw.strip()
parts = clean.split(",")
print("-".join(parts))Common mistake: parts.join("-") — that is not the Python string style; or expecting strip() to remove spaces in the middle.
Learn: cleaning, splitting into a list, and joining.
BATCH IDLE
›