Professional Documents
Culture Documents
Identifier and Keywords
Identifier and Keywords
A token is the smallest individual unit in a python program. The various tokens in python are
1.Identifiers are the names given to any variable, function, class, list, methods etc.
Here are some rules to name an identifier
• As stated above, Python is case-sensitive. So, case matters in naming identifiers. And hence print and Print are two different identifiers.
• Identifier starts with a capital letter (A-Z), a small letter (a-z) or an underscore (_). It cannot start with any other character.
• Except for letters and underscore, digits can also be a part of identifier but cannot be the first character of it.
2.Keywords:
keywords are reserved words. They cannot be used as variable names, function names, or any other random purpose. They are used for their special features. In Python we have 33 keywords some of them are: try, False,
True, class, break, continue, and, as, assert, while, for, in, raise, except, or, not, if, elif, print, import, etc.
3.Literals
Literals are generally raw data given to a variable.
Types of literals in Python
1.String literals:
A string literal can be created by writing a text (a group of Characters) surrounded by a single(”), double(“”), or triple quotes.
In [3]:
print("hello world")
hello world
2.Numeric literals:
There are three types of numeric literal: Integer ,Float and complex
In [6]:
x = 10
print(x)
print(type(x))
10
<class 'int'>
In [7]:
y = 9.8
print(y)
print(type(y))
9.8
<class 'float'>
In [8]:
z = 3+4j
print(z)
print(type(z))
(3+4j)
<class 'complex'>
3.Boolean Literal
There are only two Boolean literals in Python. They are true and false. In Python, True represents the value as 1 and False represents the value as 0.
In [10]:
a = True
print(a)
print(type(a))
True
<class 'bool'>
4.Literal Collections:
It includes List, Tuple, Dictionary, Set etc.
5.Special literals:
Python contains one special literal (None). The None keyword is used to define a null value, or no value at all.
In [11]:
a = None
print(a)
print(type(a))
None
<class 'NoneType'>
In [ ]: