Python uses literals to represent fixed values directly in the code. Literals are one of the most basic building blocks in Python programming.
In this post, we will learn what literals are, their types, and how to use them with examples.
🧠 What are Literals in Python?
Literals are fixed values that are written directly in the code.
👉 In simple words:
- Literal = raw value in code
- It does not change during program execution
⚡ Example of Literals
x = 10
name = "Python"
Here:
-
10is a numeric literal -
"Python"is a string literal
🔢 Types of Python Literals
Python supports different types of literals:
📦 1. Numeric Literals
Numeric literals represent numbers.
🔢 Integer Literal
a = 100
b = -50
🔢 Float Literal
pi = 3.14
temp = -2.5
🔢 Complex Literal
z = 2 + 3j
🔤 2. String Literals
String literals are text values written in quotes.
Example:
name = "Python"
language = 'Programming'
Multi-line string:
text = """Python is
a powerful language"""
🔁 3. Boolean Literals
Boolean literals represent truth values.
Example:
is_active = True
is_logged_in = False
👉 Only two values exist:
- True
- False
📚 4. Special Literal (None)
None represents absence of value.
Example:
x = None
print(x)
📦 5. Collection Literals
Python also supports collection-based literals.
📋 List Literal
fruits = ["apple", "banana", "mango"]
📦 Tuple Literal
colors = ("red", "green", "blue")
🔑 Dictionary Literal
student = {"name": "Python", "age": 25}
🔷 Set Literal
numbers = {1, 2, 3, 4}
⚙️ 6. Binary, Octal, and Hex Literals
Python also supports different number systems.
🔵 Binary Literal
b = 0b1010
🟡 Octal Literal
o = 0o12
🔴 Hexadecimal Literal
h = 0xA
🧪 7. Literal Example Program
name = "Python"
version = 3.12
is_easy = True
numbers = [1, 2, 3]
print(name)
print(version)
print(is_easy)
print(numbers)
⚖️ Python Literals Summary Table
| Type | Example |
|---|---|
| Integer | 10 |
| Float | 3.14 |
| String | "Hello" |
| Boolean | True |
| None | None |
| List | [1,2,3] |
| Tuple | (1,2,3) |
| Set | {1,2,3} |
| Dictionary | {"a":1} |
🚀 Why Literals are Important?
Literals are used in:
- Storing fixed values 🧾
- Writing expressions ➗
- Building programs 🧑💻
- Data processing 📊
🧾 Conclusion
Python literals are the simplest way to represent data directly in code. They are the foundation of variables, expressions, and programming logic.
💡 Final Thought
If you understand literals well, you can easily understand how Python stores and processes data.


0 Comments