Last Updated : 15 Jul, 2025
Literals in Python are fixed values written directly in the code that represent constant data. They provide a way to store numbers, text, or other essential information that does not change during program execution. Python supports different types of literals, such as numeric literals, string literals, Boolean literals, and special values like None. For example:
In this article, we'll explore various types of literals in Python with examples to demonstrate their usage:
Numeric LiteralsNumeric literals represent numbers and are classified into three types:
# Integer literals
a = 100
b = -50
# Floating-point literals
c = 3.14
d = -0.005
# Complex number literals
e = 4 + 7j
f = -3j
print(a, b, c, d, e, f)
100 -50 3.14 -0.005 (4+7j) (-0-3j)String Literals
String literals are sequences of characters enclosed in quotes. They are used to represent text in Python.
Types of String Literals:'''This is a multi-line string'''
# Different string literals
a = 'Hello' # Single-quoted
b = "Python" # Double-quoted
c = '''This is
a multi-line string''' # Triple-quoted
d = r"C:\Users\Python" # Raw string
print(a)
print(b)
print(c)
print(d)
Hello Python This is a multi-line string C:\Users\PythonBoolean Literals
Boolean literals represent truth values in Python. They help in decision-making and logical operations. Boolean literals are useful for controlling program flow in conditional statements like if, while, and for loops.
Types of Boolean Literals:
# Boolean literals
a = True
b = False
print(a, b) # Output: True False
print(1 == True) # Output: True
print(0 == False) # Output: True
print(True + 5) # Output: 6 (1 + 5)
print(False + 7) # Output: 7 (0 + 7)
Explanation:
Python provides four different types of literal collections:
Rank = ["First", "Second", "Third"] # List
colors = ("Red", "Blue", "Green") # Tuple
Class = { "Jai": 10, "Anaya": 12 } # Dictionary
unique_num = {1, 2, 3} # Set
print(Rank, colors, Class, unique_num)
['First', 'Second', 'Third'] ('Red', 'Blue', 'Green') {'Jai': 10, 'Anaya': 12} {1, 2, 3}
Explanation:
Python contains one special literal (None). 'None' is used to define a null variable. If 'None' is compared with anything else other than a 'None', it will return false.
Python
Explanation: None represents "nothing" or "empty value."
Difference between LiteralsType of Literals
Description
Example
Mutable/Immutable
Integer literals
Whole numbers (without decimals).
a = 77
Immutable
Float literals
Numbers with a decimal point.
b=3.144
Immutable
Complex literals
Numbers with real and imaginary part.
c = 7 + 5j
Immutable
String literals
Stores text. Can use single, double, or triple quotes.
greeting = "Bonjour"
story = """Once upon a time..."""
Immutable
Boolean literals
Represents True (1) or False (0).
a = (1 == True) → True
b = (1 == False) → False
Immutable
Boolean as Number
Boolean values can act as numbers (1 or 0).
c = True + 3 → 4
d = False + 7 → 7
Immutable
List literal
Stores multiple values; can be changed.
Rank = ["First", "Second", "Third"]
Mutable
Tuple literal
Like a list but cannot be changed.
colors = ("Red", "Blue", "Green")
Immutable
Dictionary literal
Stores key-value pairs.
Class = { "Jai": 10, "Anaya": 12 }
Mutable
Set literal
Stores unique values, unordered.
unique_num = {1, 2, 3}
Mutable
Special literal
Represents "nothing" or "empty."
water_remain = None
Immutable
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4