What are literals in python?
Literals in Python refer to fixed, constant values that are directly used within your code. They represent various data types, such as numbers, strings, and Boolean values. Here's an explanation of different types of literals with examples:
Numeric literals represent numbers and can be integers, floating-point numbers, or complex numbers.
String literals represent sequences of characters enclosed in single, double, or triple quotes.
Boolean literals represent truth values and can only be True or False.
The None literal represents the absence of a value. It is often used to indicate that a variable has no value assigned.
List literals represent ordered collections of items enclosed in square brackets.
Tuple literals represent ordered collections of items enclosed in parentheses.
Dictionary literals represent key-value pairs enclosed in curly braces.
Set literals represent unordered collections of unique items enclosed in curly braces.
Literals are fundamental building blocks in Python programs, providing values that can be used in calculations, comparisons, and various operations. They help represent data in a concise and straightforward manner.