Important Notice:

Variable vs Constant

Variable vs Constant

1 views 1 min read

Variable vs Constant (वैरिएबल और कॉन्स्टैंट में अंतर) :-

Variable (वैरिएबल) और Constant (कॉन्स्टैंट) दोनों का उपयोग Program में Data (डेटा) को Store (संग्रहित) करने के लिए किया जाता है। अंतर केवल इतना है कि Variable की Value Program के दौरान बदली जा सकती है, जबकि Constant की Value सामान्यतः नहीं बदली जाती

Python में Constant के लिए कोई const Keyword नहीं होता। इसलिए Constant केवल Naming Convention (नामकरण परंपरा) द्वारा दर्शाया जाता है और उसका नाम सामान्यतः UPPERCASE में लिखा जाता है।

English

Both Variables and Constants are used to store data in a program. The main difference is that the value of a variable can change during program execution, whereas the value of a constant is intended to remain unchanged.

Python does not have a const keyword. Therefore, constants are represented only by a naming convention and are usually written in UPPERCASE.

Example :-

# Variable
age = 20

# Constant (Naming Convention)
PI = 3.14159

print(age)
print(PI)

# Changing the values
age = 21          # Recommended
PI = 22 / 7       # Allowed, but Not Recommended

print(age)
print(PI)
 
Output-
20
3.14159
21
3.142857142857143
Explanation (व्याख्या) -

ऊपर दिए गए Program में:

  • age एक Variable है क्योंकि इसकी Value 20 से 21 कर दी गई।
  • PI एक Constant है। Python इसकी Value बदलने की अनुमति देता है, लेकिन इसे बदलना Good Programming Practice (अच्छी प्रोग्रामिंग पद्धति) नहीं माना जाता।

Related Notes