Printing and PDF export are disabled for this content. View it online at Full Stack Learning Simplified.
Working with Stringsπ± Beginner
Strings in Python are immutable sequences of characters, with a large set of built-in methods and several ways to format them.
Creating and combining strings
example.py
single = 'hello'
double = "world"
multiline = """This spans
multiple lines"""
combined = single + " " + double # "hello world"f-strings β the modern way to format
An f-string (prefix f) lets you embed expressions directly inside { } β it's the preferred formatting approach in modern Python, replacing older %-formatting and .format() calls for most cases.
example.py
name = "Ada"
age = 30
print(f"{name} is {age} years old")
print(f"Next year: {age + 1}") # expressions work inline
print(f"{3.14159:.2f}") # "3.14" β format specifiers tooCommon string methods
example.py
s = " Hello, World! "
s.strip() # "Hello, World!" β remove leading/trailing whitespace
s.lower() # " hello, world! "
s.replace("l", "L") # " HeLLo, WorLd! "
s.split(",") # [" Hello", " World! "]
"-".join(["a","b","c"]) # "a-b-c"
s.strip().startswith("Hello") # TrueStrings are immutable
Every string method returns a new string rather than modifying the original in place β s.upper() doesn't change s, it returns a new uppercase string you must assign somewhere if you want to keep it.
example.py
s = "hello"
s.upper() # returns "HELLO" but s is still "hello"
s = s.upper() # now s is "HELLO"Python Concept Takeaway: Python features high-level dynamically-typed syntax, automatic memory management, and batteries-included standard libraries.
Python Productivity Tip: Use type hints (
def process(items: list[str]) -> bool:) and run mypy for static type checking in larger codebases.Free preview. Sign in and subscribe to unlock all 982 lessons across 31 courses.
Free preview Β· Β© 2026 Full Stack Learning Simplified