Literals in Python
A literal is a fixed value written directly into your code — 42, "Ada", True, and [1, 2, 3] are all literals. This is different from a variable, which is a name that points to a value; a literal is the value itself, spelled out exactly as it will be used.
Python recognizes several categories of literal by their shape alone: digits form a number, characters in quotes form a string, True/False/None are their own special literals, and brackets or braces build a collection on the spot. Recognizing these categories at a glance is really about knowing what kind of object a piece of code is building.
Numeric literals
Whole numbers (42), decimals (3.14), and complex numbers (2+3j) written directly — Python decides int vs float based on whether a decimal point is present.
String literals
Text wrapped in single, double, or triple quotes — triple quotes additionally allow the string to span multiple lines.
Boolean literals
Exactly two values, always capitalized: True and False.
The None literal
A single, unique value representing "no value here" — not zero, not an empty string, and not False.
Collection literals
Lists [ ], tuples ( ), dictionaries { key: value }, and sets { } — Python recognizes the surrounding brackets or braces and builds the corresponding object immediately.
count = 42price = 19.99is_ready = Trueresult = Nonename = "Ada"scores = [88, 92, 76] print(count, price, is_ready, result, name, scores)Numeric Literals
int, float, and complex values written directly. Underscores can be used as visual separators in long numbers — Python ignores them entirely.
big_number = 1_000_000pi_estimate = 3.14159print(big_number, pi_estimate)String Literals
Text in single or double quotes — functionally identical, so pick whichever lets you avoid escaping a quote character inside the string.
greeting = 'Hi'quote = "She said 'hello' back"print(greeting, quote)Collection Literals
Lists, tuples, and dictionaries can all be built in a single line using their own bracket style, with no separate "create an empty one and fill it" step required.
nums = [1, 2, 3]point = (4, 5)person = {"name": "Ada"}print(nums, point, person)Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Python yourself — building beats watching.