Python Literals:
Literals are the constant values or the variable values used in a Python code. There are mainly five types of literals used in PYTHON:
- String Literals
- Numeric Literals
- Boolean Literals
- Special Literals
- Collection Literals
String literals:
In Python, String literals are characterised either by single quotation marks, or double quotation marks surrounding them. The string literals can be Single line or Multiple line strings.
Numeric literals:
Numeric Literals in Python can be of three numeric types:
- int
- float
- complex
1. Int
Int can be defined as a collection of both positive and negative integers (without decimals).
2. Float
Float can be defined as a collection of both positive and negative floating point numbers (with decimals) along with the scientific numbers with an “e” to indicate the power of 10.
3. Complex
Complex numbers are the numbers having both a real and imaginary part in the form of x +yj, where x is real and y is imaginary.
Boolean literals:
Boolean literals can be either 0 or 1 i.e, either True or False.
Special literals.
None is a special literal defined in Python to specify the end of a list or to represent a NULL value.
Literal Collections.
Beside Lists, Python supports Tuples and Dictionary to store a collection of literals in a single variable.