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 02
Second class. You can already read characters. Now come basic tools for the whole string.
len(text) returns the character count (spaces included). The in operator checks whether a substring appears: "Lab" in msg is True or False.
Methods return a new string (the original does not change unless you reassign): - upper() / lower() — uppercase / lowercase - find(sub) — index of the first match, or -1 if missing - replace(old, new) — replaces occurrences of old with new
Mini example:
msg = "Hi Lab"
print(len(msg))
print("Lab" in msg)
print(msg.upper())
print(msg.find("Lab"))
print(msg.replace("Lab", "World"))Common mistake: expecting msg.upper() to change msg without assignment; or confusing find with a list index. We do not use strip, split, or join yet — that is the next lesson.
Learn: basic checks and methods on a string (no strip/split/join yet).
MODULES IDLE
›