Skip to content
Learn Netverks

Lesson

Step 8/36 22% through track

strings-python

Strings in Python

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Strings in Python: the syntax, patterns, and safety habits you need before advancing in Python.

Teams still ship Strings in Python in Python codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Strings in Python in contexts like: Scripts, Django/FastAPI apps, notebooks, and glue code between systems.

Write Python 3 in the editor and click Run on server—the dev runner executes your script with print() for output; stdlib only in playground snippets (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Python str is immutable Unicode text. Concatenation uses +, but f-strings (f"...") are the idiomatic way to embed expressions—cleaner than % formatting or .format().

f-strings and literals

name = "Ada"
msg = f"Hello, {name}!"
path = r"C:\logs\app.txt"  # raw string: backslashes literal
multiline = """line one
line two"""

Common string methods

"hello".upper()
"  trim  ".strip()
"a,b,c".split(",")
",".join(["a", "b", "c"])

Strings are immutable—methods return new strings. For heavy building, use io.StringIO or join lists of parts.

Important interview questions and answers

  1. Q: Why are strings immutable?
    A: Hash stability for dict keys, thread-safe sharing, and predictable behavior—like Java strings.
  2. Q: f-string vs + concatenation?
    A: f-strings are readable and efficient; repeated + in loops allocates many interim strings.

Self-check

  1. What prefix creates a raw string?
  2. Does upper() mutate the original string?

Tip: Prefer f-strings over + in loops—strings are immutable and repeated concat allocates interim objects.

Interview prep

f-string vs format?

Both work; f-strings embed expressions inline and are the modern default for readability.

Immutable strings?

Methods like upper() return new strings—original unchanged, enabling safe dict keys and hashing.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • f-string when?
  • immutable str?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump