Tokens are the smallest unit of program. There are following tokens in Python:

  • Reserved words
  • Identifiers
  • Literals
  • Operators

 
Reserved Words 
Reserved Words are also known as keywords which express a special meaning to the compiler and interpreter. Keywords in python are –

returnorNoneandnot
assetdefclasscontinuebreak
fromfinallyelifdelexcept
globalforifelseimport
raisetryTrueFalsepass
nonlocalinasislambda

 
Identifiers
An identifier is a sequence of numbers and characters. These are the names given to the basic building blocks in a program. These can be class, variables, functions, object, lists, dictionaries etc.
Rules for defining identifiers are –

  • First character of an identifier can be character, underscore ( _ ) but not digit.
  • No special character except underscore ( _ ) can be used as an identifier.
  • Reserve words cannot be used as an identifier name.
  • Python is a case sensitive language so ‘a’ and ‘A’ are different identifiers.

 
Literals
Literals can be defined as a data that is given in a variable or constant. Python have following literals:-

  • String Literals
  • Numeric Literals
  • Floating Literals
  • Boolean Literals
  • Collection literals

 
Variables
A variable is a memory address that can change and when memory address cannot change then it is known as constant. Variable is a name of the memory location where data is stored. Once a variable is stored then space is allocated in memory. It defines a variable using a combination of numbers, letters and the underscore character.
There are a few rules: a variable must begin with a letter or an underscore, and the variable name is case sensitive.
 
Assigning Values to Variables
There is no need for explicit declaration to reserve memory. The assignment is done using the equal (=) operator. Some example of legal python variables are –

i = 1
i_j = 2

Example 

>>> a = 1
print a

Output
1
 
Multiple Assignment:
You can assign a single value to the multiple variables as follows –

a = b = c = 20

Where a, b, c are the variable.
Also you can assign multiple values to the multiple variables as follows –

a = b = c = 20, 25, 30
print a
print b
print c

Output
20
25
30
Learn more about PYTHON TOOLKIT in this insightful blog now!

Recommended Videos

Leave a Reply

Your email address will not be published. Required fields are marked *