← Lesson
BitWithBite
Python · Quick Reference

Lesson 3 — Strings & Text Cheat Sheet

Python
In one line: A string is a sequence of characters — letters, digits, spaces, symbols, or even emojis — wrapped in quotes. Strings are one of the most used data types in any programming langu...

Key Ideas

1What is a String?. A string is a sequence of characters — letters, digits, spaces, symbols, or even emojis — wrapped in quotes. Strings are one of the most used data types in any program...
2Indexing & Slicing. Every character in a string has a position number called an index. Python indexes start at 0 (not 1!). You can also count from the end using negative indexes — -1 is a...
3Essential String Methods. Python strings come with 50+ built-in methods. You call them with dot notation: string.method(). Here are the most important ones you'll use daily.
4f-Strings — Modern String Formatting. An f-string (formatted string literal) is the modern, clean way to embed variables and expressions directly inside a string. Prefix the string with f and put variables...
5Escape Characters. Some characters can't be typed directly inside a string — like a newline, a tab, or a backslash. You use an escape sequence: a backslash \ followed by a special charac...

Code Examples

# Three ways to create strings single = 'Hello, Python!' # single quotes double = "Hello, Python!" # double quotes (same result) triple = """This string spans multiple lines.""" # triple quotes = multi-line print(sin...
lang = "Python" # Positive indexing print(lang[0]) # P — first character print(lang[1]) # y print(lang[5]) # n — last character # Negative indexing print(lang[-1]) # n — last character print(lang[-6]) # P — first character # IndexError — goin...
text = "BitWithBite" # Basic slice: [start:stop] (stop is excluded) print(text[0:3]) # Bit (chars at 0,1,2) print(text[3:7]) # With print(text[7:]) # Bite (omit stop = go to end) print(text[:3]) # Bit (omit start = from beginning) print(...