Literals in Python (original) (raw)

Last Updated : 11 Jun, 2026

Literals are fixed values written directly in Python code. They represent constant data such as numbers, strings, Boolean values and special values and can be assigned to variables or used directly in expressions.

Numeric Literals

Numeric literals represent numeric values written directly in the code. Python supports three main types of numeric literals:

a = 100 b = -50 c = 3.14 d = -0.005 e = 4 + 7j f = -3j

print(a, b, c, d, e, f)

`

Output

100 -50 3.14 -0.005 (4+7j) (-0-3j)

**Explanation:

String Literals

String literals represent text and are created by enclosing characters within quotes. Python supports several ways to define strings depending on the use case.

a = 'Hello' b = "Python" c = '''This is a multi-line string''' d = r"C:\Users\Python"

print(a) print(b) print(c) print(d)

`

Output

Hello Python This is a multi-line string C:\Users\Python

**Explanation:

Boolean Literals

Boolean literals represent logical truth values in Python. They are commonly used in conditions, comparisons, and decision-making statements.

a = True b = False

print(a, b) print(1 == True) print(0 == False) print(True + 5) print(False + 7)

`

Output

True False True True 6 7

**Explanation:

Collection Literals

Collection literals are used to create multiple values in a single object. Python provides four main collection literals:

ranks = ["First", "Second", "Third"] colors = ("Red", "Blue", "Green") students = {"Jai": 10, "Anaya": 12} nums = {1, 2, 3}

print(ranks) print(colors) print(students) print(nums)

`

Output

['First', 'Second', 'Third'] ('Red', 'Blue', 'Green') {'Jai': 10, 'Anaya': 12} {1, 2, 3}

**Explanation:

Special Literal

Python provides a special literal called None, which represents the absence of a value or a null value. It is commonly used to indicate that a variable currently has no meaningful value assigned to it.

Python `

res = None print(res)

`

**Explanation: None is a special value that represents the absence of a value.

Comparison of Python Literals

Literal Type Description Example Mutable / Immutable
Integer Literal Represents whole numbers without a decimal point. a = 77 Immutable
Float Literal Represents numbers containing a decimal point. b = 3.144 Immutable
Complex Literal Represents numbers with real and imaginary parts. c = 7 + 5j Immutable
String Literal Represents text enclosed in single, double, or triple quotes. greeting = "Bonjour" Immutable
Boolean Literal Represents logical values True and False. flag = True Immutable
List Literal Stores multiple ordered values that can be modified. ranks = ["First", "Second", "Third"] Mutable
Tuple Literal Stores multiple ordered values that cannot be modified. colors = ("Red", "Blue", "Green") Immutable
Dictionary Literal Stores data as key-value pairs. students = {"Jai": 10, "Anaya": 12} Mutable
Set Literal Stores unique unordered values. nums = {1, 2, 3} Mutable
Special Literal (None) Represents the absence of a value. result = None Immutable