Variable Assignment
- When you create a variable you keep some space in memory. These memory locations are then used to store values.
# define a variable name "a" and assign value 5 to it a = 5
- To view some data on the output screen, python also has
print
function. Usingprint
function we can control the view on the output screen.
print(a)
Variable naming rules
Identifiers in Python
- Like Variables, we have to define functions, classes, etc in python. Naming them helps to differentiate one entity from another.
- All these names given to these entities are known as Identif
- Python have some rules to define the Identifiers.
Rules of Writing Identifiers
- Python is case sensitive language.
- Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore _. Names like myVariable, var_1 and print_this, all are valid example.
- An identifier cannot start with a digit.
- 1variable is invalid, but variable1 is perfectly fine.
- We cannot use special symbols like !, @, #, $, % etc. in our identifier. _ is allowed.
Keywords cannot be used as identifiers. `Keywords` are the reserved words in Python.
Keywords in Python
- False
- class
- finally
- is
- return
- None
- continue
- for
- lambda
- try
- True, etc
Data types
- int
- string
- float
- bool
# INTEGER TYPE
a = 5
To check the data type of a variable
type(a)
Another Example
# STRING TYPE
b = "lakshay"
type(b)
# FLOAT TYPE
c = 5.55
type(c)
# BOOLEAN TYPE
d = True
type(d)