Saturday, 3 February 2018


Before starting with our next data Type, Let’s first know about variables in python:
Variables :
    These are any names which can be assigned any data type:
Python has no restrictions on use of variables, We don’t need
any explicit declaration of type of variable. Python assigns
data type of the variable by the data it holds.
Confused, correct?? Let’s take an example:
    >>> a = 3
Is a variable declaration where, a is  variable name and 3 is an
int data type assigned to it.
>>> type(a)
<class 'int'>
You can overwrite same  variable to hold value of same or different data type.
    >>> a = 32
>>> a = 45
>>> a
45
>>> a = "string"
>>> a
'string'
>>> type(a)
<class 'str'>

Using variable to access the data it is storing.
>>> a = 23
>>> b = 3
>>> a+b
26
>>> a**b
12167
One of the best things what python provides is simultaneous
assignment of variables.
For example :
>>> a,b = 12,"string"
>>> a
12
>>> b
'string'

>>> a, b, c = 2,1,    9
>>> a+b+c
12

No comments:

Post a Comment

Memoization : Memoization is a technique for remembering the results that incur huge costs to running time to the algorithm. Memoizati...