Python | Variables, Their Rules & Types By. Shivansh Sir
PYTHON PROGRAMMING
PYTHON | VARIABLES
Variable जब create किया जाता है तब interpreter द्वारा value को store करने के लिए memory location reserved की जाती है | Variable पर कोई भी data type की value store की जा सकती है | जैसे कि, Number, string, list, tuple, dictionary, etc
PYTHON | VARIABLES | ASSIGNING VALUE TO VARIABLES
Python में declaration की जरुरत नहीं होती है | जब variable पर value assign होती है तब automatically declaration होता है | Declaration न होने के कारण Python में variable की default value नहीं होती है |
Example
a = 5 #Number
b = "Hello" #string
c = [2, 5, 9] #list
Source Code
print(a, b, c)
Output
5 Hello [2, 5, 9]
PYTHON | VARIABLES | CHANGING VARIABLE'S VALUE
Python में variable की value change या re-assign की जा सकती है |
Source Code
a = 5
print(a)
a = "Hello"
print(a)
a = [4, 5, 8]
print(a)
Output
5
Hello
[4, 5, 8]
PYTHON | VARIABLES | ASSIGNING SINGLE VALUE TO MULTIPLE VARIABLES
Source Code
a = b = c = d = "Hello"
print(a)
print(b)
print(c)
print(d)
Output
Hello
Hello
Hello
Hello
PYTHON | VARIABLES | Assigning Value to Variable according to order
Source Code
a, b, c = 1, 'H', [1, 2]
print(a)
print(b)
print(c)
Output
1
H
[1, 2]
PYTHON | VARIABLES | VARIABLE CONCATENATION
Source Code
a = 1
b = 2
print(a + b)
print(str(a) + str(b))
c = "Hello"
print(str(a) + c)
Output
3
12
1Hello
PYTHON | VARIABLES | TYPES OF VARIABLES
Comments
Post a Comment