What are 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
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 in Python can be of three numeric types:
Int can be defined as a collection of both positive and negative integers (without decimals).
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.
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 can be either 0 or 1 i.e, either True or False.
None is a special literal defined in Python to specify the end of a list or to represent a NULL value.
Beside Lists, Python supports Tuples and Dictionary to store a collection of literals in a single variable.