Write a short note on literals in Python.
Answer:
Literals are data items that have a fixed value.
Python has the following 4 literals:
1. String literals : the text enclosed in quotes (single or double) is considered to be a string literal.
Examples:
- “abc”
- ‘d’
- “123start”
2. Numeric literals: Numeric literals can be of type int, float or complex.
Examples:
- 10
- 3.1497
- 2+3i
3. Boolean literals: It represents one of the two Boolean values.
Examples:
- True
- False
4. Special literals: None is a special literal that indicates absence of a value and is generally used to indicate end of lists in python. It means that there is no useful information.