Variables:
Variables are reserved memory locations to store data or values. When we create a variable, we are actually reserving space in the memory.
As suggested by the name, the values in the variables can be changed at any time by the programmer.
Variables Declaration:
In Python you can directly use variables without declaration. No datatype is needed here, means
x=8 (here x is of int type)
x=9.7 (here x is of float type)
x="hacking" (here x is of string type)
That's why Python is called dynamically typed language.
This can be demonstrated using a simple python script as show below:
x=5
print(type(x)) #int
x=5.0
print(type(x)) #float
Note: In Python language, we actually create reference variable. This can be understood as, suppose we write
x=5
print(id(x))
then we are creating reference variable x which is pointing to the address in which value is 5.
Variable Naming Rules:
A name of a variable can be a combination of alphabets, digits, and underscores.
A name cannot be start with a digit.
Variable names are case sensitive.
Keywords cannot be used as variable name.
Variable names can be start with underscore also.
Object:
Object is something which is capable of storing set of values. Every variable in python is object. Object can be defined as an instance of class.
Keywords in Python3:
Predefined words or reserved words are called keywords. As their function is already defined they cannot be used as variable names.
Python has 33 keywords.
Script: How to see all keywords in Python?
import keyword #module
print(keyword.kwlist)
Note: There are only three keywords in python which starts from capital letters. These are as:
True, False, None
Variables are reserved memory locations to store data or values. When we create a variable, we are actually reserving space in the memory.
As suggested by the name, the values in the variables can be changed at any time by the programmer.
Variables Declaration:
In Python you can directly use variables without declaration. No datatype is needed here, means
x=8 (here x is of int type)
x=9.7 (here x is of float type)
x="hacking" (here x is of string type)
That's why Python is called dynamically typed language.
This can be demonstrated using a simple python script as show below:
x=5
print(type(x)) #int
x=5.0
print(type(x)) #float
Note: In Python language, we actually create reference variable. This can be understood as, suppose we write
x=5
print(id(x))
then we are creating reference variable x which is pointing to the address in which value is 5.
Variable Naming Rules:
A name of a variable can be a combination of alphabets, digits, and underscores.
A name cannot be start with a digit.
Variable names are case sensitive.
Keywords cannot be used as variable name.
Variable names can be start with underscore also.
Object:
Object is something which is capable of storing set of values. Every variable in python is object. Object can be defined as an instance of class.
Keywords in Python3:
Predefined words or reserved words are called keywords. As their function is already defined they cannot be used as variable names.
Python has 33 keywords.
Script: How to see all keywords in Python?
import keyword #module
print(keyword.kwlist)
Note: There are only three keywords in python which starts from capital letters. These are as:
True, False, None
Be First to Post Comment !
Post a Comment