Learn Python
>>> getting_started.literals

Literals in Python

#concept

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.

#how it works
1

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.

2

String literals

Text wrapped in single, double, or triple quotes — triple quotes additionally allow the string to span multiple lines.

3

Boolean literals

Exactly two values, always capitalized: True and False.

4

The None literal

A single, unique value representing "no value here" — not zero, not an empty string, and not False.

5

Collection literals

Lists [ ], tuples ( ), dictionaries { key: value }, and sets { } — Python recognizes the surrounding brackets or braces and builds the corresponding object immediately.

#example
count = 42
price = 19.99
is_ready = True
result = None
name = "Ada"
scores = [88, 92, 76]
 
print(count, price, is_ready, result, name, scores)
Output
42 19.99 True None Ada [88, 92, 76]
1Each line assigns a literal value directly to a name — no computation and no function call, just the raw value exactly as written.
242 and 19.99 are numeric literals; the decimal point is the only thing that tells Python to treat one as an int and the other as a float.
3True is a boolean literal, and None is its own literal entirely — distinct from both 0 and False, even though all three can feel "empty" at a glance.
4"Ada" is a string literal and [88, 92, 76] is a list literal — Python recognizes the quotes and the brackets and builds each object immediately.
#variants

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_000
pi_estimate = 3.14159
print(big_number, pi_estimate)
Output
1000000 3.14159

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)
Output
Hi She said 'hello' back

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)
Output
[1, 2, 3] (4, 5) {'name': 'Ada'}
#use cases
Choosing the right literal type up front — 19.99 as a float vs "19.99" as a string — to avoid subtle bugs when the value is used in a calculation later
Reading unfamiliar code faster, once you can instantly recognize literal syntax for each type
Using underscore separators (1_000_000) to keep long numeric literals readable in financial or scientific code
Using None as a clean "no value yet" placeholder before a variable is properly initialized

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Python yourself — building beats watching.