Tokens are Building blocks of Python programming language.
What are tokens?
Tokens in python are building blocks of Python programming language.
The role letters and words play for the English language, Similar role token play for a python programming language.
Python has following tokens:-
d>Special literal None
Keywords are reserved words having a special purpose.For example:-True,False,for,elif .
Their purpose has already been defined, you cannot change it. When you name any variable as a keyword and try to assign some value to it, it will throw an error.
>>> False=10 File "<stdin>", line 1 SyntaxError: can't assign to keyword
Identifiers are Names given to variables, functions, class etc.
What is a variable?
Variables are containers for storing data values. Python has no command for declaring a variable. A variable is created the moment you first assign a value to it.
Think of variables as an address and data/value as your belongings. whenever you need your belongings you visit your address. Similarly, whenever in programming, you need your data/value you visit your variable.
The variable myName contains the value Anish, whenever I need that value I will use the variable myName.
conditions for naming variables
1> A variable name must start with a letter or the underscore character.
2> A variable name cannot start with a number.
3>A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ).
4>Variable names are case-sensitive (age, Age, and AGE are three different variables).
_myName='Anish' print(_myName) >>>Anish
2myName='Anish' File "<ipython-input-3-2be3ad01e93c>", line 1 2myName='Anish' ^ SyntaxError: invalid syntax
Best practice for naming a variable
variables names should be in lower case.
variables names should not be list, str, or any keyword.
So, refrain from using such names as variable names.
In many languages, while declaring a variable you have to mention the type of that variable. While storing the value in that variable you
have to adhere to that type.
for example, in java, you declare a variable like
###here int is data type and myVariable is variable name. int myVariable
In variable myVariable(declared above) you can store only an integer. So, java is Statically typed.
if in myVariable you assign anything other than integer it will throw an error.
Python is dynamically typed,i.e different data types can be assigned to the same python variables.
We do not have to mention data type in python variable declaration or assignment.
Variable dynamically takes type based on the value assigned to it.
myname='anish' myname=100 myname=100.20 print(myname) >>>100.20
you are assigning different data types to the same variable myname, that is why python is dynamically typed .you can reassign variable to different data types.
Literals are constant value which do not change.
File "<ipython-input-8-a18697708789>", line 1 False=10 ^ SyntaxError: can't assign to keyword
File "<ipython-input-9-d0236c79ad3e>", line 1 2name='anish' ^ SyntaxError: invalid syntax
Literals Literals are constant value which do not change.
#String literal "Subham is a good guy"
'Subham is a good guy'
#numeric literal 10
#boolean literal True
#boolean literal False
Next:- Basic Data Types in Python