Notes / Python / Strings

Strings in Python — Revision Notes

A quick-reference cheat sheet: definition, syntax, example, common mistakes and an interview tip.

beginner 📖 2 min revision

Definition

📌 Strings Python strings (str) are sequences of characters, and like lists, they support indexing and slicing.

Syntax

syntax
name = "text"
name[0]         # first character
name[0:3]       # slice
f"Hello, {name}!"

Example

py
name = "CodeyHub"
print(f"Name: {name}")
print("Length:", len(name))
print("Upper:", name.upper())

Output

outputName: CodeyHub Length: 8 Upper: CODEYHUB

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview Know Python string slicing well — s[::-1] to reverse a string is a very common quick interview trick.
Back to notes Read full lesson →