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:

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 example demonstrating different types of literals in Python:

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

# Integer literal
age = 30

# Floating-point literal
pi = 3.14159

# Boolean literal
is_active = True

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

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

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

Tutorial

Basic Data Types in Python: A Quick Exploration

In this tutorial, you'll learn about the basic data types that are built into Python, including numbers, strings, bytes, and Booleans.

basics python

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


By Leodanis Pozo Ramos • Updated April 22, 2025