Python Variables In Hindi (Python Variables कितने प्रकार के होते हैं ?)

Python

Python Variables In Hindi

नमस्कार दोस्तो इस आर्टिकल में हम जानेंगे कि Python Variable क्या होते हैं ? और Python Variable कितने प्रकार के होते हैं ?

What is Variable 

Python में जब Variable create किया जाता है तब interpreter द्वारा value को store करने के लिए memory location आरक्षित की जाती है | 

Variable पर कोई भी data type की value store की जा सकती है | जैसे कि, Number, string, list, tuple, dictionary. 

Rules Of Python Variable 

Assigning Value to Variable Python में declaration की जरुरत नहीं होती है | जब variable पर value assign होती है तब automatically declaration होता है | 

declaration न होने के कारण Python में variable की default value नहीं होती है | 

Example :

a = 5      #Number
b = "Hello" #string
c = [2, 5, 9] #list

print(a, b, c)
Output :

5 Hello [2, 5, 9]

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]

Assigning Single Value to Multiple Variables 

Python में एक ही value एक से ज्यादा variables पर assign की जा सकती है | 

Source Code :

a = b = c = d = "Hello"
print(a)
print(b)
print(c)
print(d)
Output :

Hello
Hello
Hello
Hello

Assigning Value to Variable according to order

Python में क्रमनुसार variable पर value store की जाती है | Example पर एक ही memory location multiple variables और उनकी values assign की गयी है |


Python

Source Code :

a, b, c = 1, 'H', [1, 2]
print(a)
print(b)
print(c)
Output :

1
H
[1, 2]

Variables Concatenation

Python में एक ही data types के variables concatenate किय जा सकते है | 
Example पर str() function का इस्तेमाल object को integer से string में convert करने के लिए किया गया है | 

Source Code :

a = 1
b = 2
print(a + b)
print(str(a) + str(b))
c = "Hello"
print(str(a) + c)
Output :

3
12
1Hello

Types of Variable in Python

Python में दो प्रकार Variable होते हैं - 

Local Variables 

Global Variables 

How to create Python Variables 

1. Local Variables 

Local Variables; functions के अन्दर होते हैं | उनकी visibility सिर्फ function के अन्दर होती है, जब वो function के बाहर आते हैं तब destroy हो जाते हैं | 

Source Code :

def func():
    a = 5 #local variable
    print(a)

func()
print(a)
Output :

5
Traceback (most recent call last):
    print(a)
NameError: name 'a' is not defined

2. Global Variables 

Global Variables; function के बाहर होते हैं | उनकी visibility function के अन्दर और बाहर होती है | उनका scope पूरे program पर होता है | 


 Source Code :

a = 10 #global variable
def func():
    print(a)

func()
print(a)
Output :

10
10


अगर आपको यह पोस्ट 📑 (Python Variables) पसंद आई हो तो अपने मित्रों के साथ जरूर शेयर करें। धन्यवाद !

Maxon

Hello there! I'm Maxon, a dedicated UI/UX designer on a mission to transform digital experiences into intuitive, user-centric journeys. With a keen eye for detail and a passion for crafting aesthetically pleasing interfaces, I strive to create designs that not only look stunning but also enhance usability and functionality.

Post a Comment

Previous Post Next Post