π’ Python Literals β Types, Examples, and Use Cases (2025)
π What Are Literals in Python?
In Python, literals are the raw, fixed values assigned to variables or used directly in expressions. These values represent data types like strings, numbers, booleans, or special values like None.
When you write:
x = 10
Here, 10 is a literal of type int.
β Types of Python Literals
1οΈβ£ Numeric Literals
Represent numbers.
| Type | Example | 
|---|---|
| Integer | 10,-5 | 
| Float | 3.14 | 
| Complex | 4+2j | 
2οΈβ£ String Literals
Represent text. Can use:
- Single quotes β 'Hello'
- Double quotes β "World"
- Triple quotes for multi-line β '''Python'''or"""Hello"""
3οΈβ£ Boolean Literals
Represent logical values:
- True
- False
These are internally treated as integers 1 and 0.
4οΈβ£ Special Literal
- Noneβ Represents a null value or absence of value.
Example:
x = None
5οΈβ£ Literal Collections
Python supports literal expressions for collections:
| Type | Example | 
|---|---|
| List | [1, 2, 3] | 
| Tuple | (10, 20) | 
| Dictionary | {"name": "Alice"} | 
| Set | {1, 2, 3} | 
These are used as literal values in collection data structures.
π Summary β Python Literals Overview
| Literal Type | Example | 
|---|---|
| Integer Literal | 10,-50 | 
| Float Literal | 3.14,-0.99 | 
| Complex Literal | 3+4j | 
| String Literal | "hello",'world' | 
| Boolean Literal | True,False | 
| Special Literal | None | 
| List/Tuple/Dict | [1, 2],("a",),{} | 
β FAQs β Python Literals
β What is a literal in Python?
A literal in Python is a fixed value that is written directly in code, such as numbers, strings, or booleans. It’s the actual value you assign to a variable.
β What are the types of literals in Python?
The main types of literals include:
- Numeric: int,float,complex
- String: 'Hello',"World"
- Boolean: True,False
- Special: None
- Collections: list,tuple,dict,set
β What is the difference between a variable and a literal?
A literal is the actual fixed value (e.g., 10), while a variable is the name that holds or refers to that value (e.g., x = 10).
β What does None mean in Python?
None is a special literal in Python that represents the absence of a value or a null value. Itβs commonly used as a default placeholder.
β Are True and False literals?
Yes, True and False are Boolean literals in Python, and they behave like integers 1 and 0 respectively in logical operations.
Share Now :
