Literals
Literals can be defined as data that is given in a variable or
constant. The values can be a number, character, string or boolean
values.
There Are Five Types Of Literals
- Numeric Literals
- String Literals
- Boolean Literals
- Special Literals
- Collection Literals
Numeric Literal:
Numeric literal are immutable(can't be changed) and it can be
an integer, float and complex values.
Example:
x=156 # Integer literal
y=100.456 # Float literal
String Literal:
String literal are
enclosed with in quotes. we can use either single or double.
Example:
'hi'
''welcome''
"""Welcome to Python"""
Boolean Literal:
Boolean literal can have
only two values either true or false.
Example:
True
False
Special Literal:
Python has only one
special literal called ''none''.
Example:
None
Collection Literal:
Literal collection
segment to specify values for a collection data type.
Example:
[1, 2, 3] # List literal
(4, 5, 6) # Tuple literal
{7, 8, 9} # Set literal
{"a": 1, "b": 2} # Dictionary literal
Identifiers
An identifiers is any name given to program element such
as variables, functions, class, variables modules or object. In python
identifiers may contain letters, digit and underscore but it should not
begin with numbers.
Example:
name
age
_total
studentMarks
Rules For Using Python Identifiers
- An identifier name should not be a keyword.
- An identifier name can begin with a letter or an underscore only.
- An identifier name can contain both numbers and letters along with the underscore(A-Z, 0-9,_)
- An identifiers name in python is case-sensitive.