✍️ Python Syntax & Basic Constructs
Estimated reading: 2 minutes 46 views

πŸ”’ 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.

TypeExample
Integer10, -5
Float3.14
Complex4+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:

TypeExample
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 TypeExample
Integer Literal10, -50
Float Literal3.14, -0.99
Complex Literal3+4j
String Literal"hello", 'world'
Boolean LiteralTrue, False
Special LiteralNone
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 :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

Python Literals

Or Copy Link

CONTENTS
Scroll to Top