Tokens and Variables
Tokens are the smallest unit of program. There are following tokens in Python:
- Reserved words
Reserved Words are also known as keywords which express a special meaning to the compiler and interpreter. Keywords in python are –
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 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
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
>>> a = 1 print a
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
Learn more about PYTHON TOOLKIT in this insightful blog now!