Skip to content

literal

In Python, a literal represents a fixed value in your code. These are the raw data elements that don’t change during execution.

Python supports literals for the following data types:

Lists, tuples, dictionaries, and sets don’t have literals in the strict sense. Python builds them with displays, such as [1, 2] or {"a": 1}, although many people informally call these list or dictionary literals.

Literals allow you to directly assign values to variables, making your code more readable and straightforward.

When you use literals, you hardcode values. This means that wherever the literal appears, it will always represent the same value. This is useful for initializing variables with known values or defining constants.

Examples

Here are some examples demonstrating different types of literals in Python:

Language: Python
# String literal
greeting = "Hello, Pythonista!"

# Integer literal
age = 30

# Floating-point literal
pi = 3.14159

# Boolean literal
is_active = True

# List display
fruits = ["apple", "orange", "mango"]

# Dictionary display
numbers = {"one": 1, "two": 2, "three": 3}

In these examples, you assign literals to variables using the assignment operator.

Basic Data Types in Python

Tutorial

Basic Data Types in Python: A Quick Exploration

Explore the Python basic data types built into the language: numbers, strings, bytes, and Booleans, and how each one behaves.

basics python

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 16, 2026 • Reviewed by Dan Bader