Python Variables क्या हैं? Variables के Rules, Types और Examples | RBSE Class 12

इस लेख में: Python Variables क्या होते हैं, variable कैसे बनाते हैं, variable naming rules, valid और invalid variable names, multiple variables, data types के साथ variables, type() function और practical Python examples आसान हिंदी में सीखेंगे।

Python Variable क्या है?

Programming में हमें अलग-अलग प्रकार की values को computer की memory में काम करने के लिए रखना पड़ता है। Python में किसी value को एक नाम के साथ associate करने के लिए variable का उपयोग किया जाता है।

सरल शब्दों में, Variable एक नाम है जिसके माध्यम से हम किसी value को refer कर सकते हैं।

उदाहरण:

name = "Rahul"
age = 18
marks = 85.5

ऊपर दिए गए program में name, age और marks variables हैं।

Python में Variable कैसे बनाते हैं?

Python में सामान्य variable assignment के लिए अलग से data type लिखने की आवश्यकता नहीं होती। Variable को value assign करके बनाया जा सकता है।

name = "Rahul"
age = 18
city = "Jaipur"

यहाँ = assignment operator का उपयोग variable को value assign करने के लिए किया गया है।

याद रखें: Python में = का अर्थ सामान्य mathematics में "बराबर" नहीं, बल्कि किसी variable को value assign करना है।

Variable Assignment क्या है?

किसी variable को कोई value देना assignment कहलाता है।

x = 10

इस statement में x variable को 10 value assign की गई है।

एक और उदाहरण:

student_name = "Amit"
student_age = 17
student_marks = 92

Python Variable Naming Rules

Python में variable का नाम बनाते समय कुछ rules का पालन करना आवश्यक है।

  1. Variable का नाम letter या underscore (_) से शुरू हो सकता है।
  2. Variable के नाम में letters, numbers और underscore का उपयोग किया जा सकता है।
  3. Variable का नाम number से शुरू नहीं किया जा सकता।
  4. Variable के नाम में spaces का उपयोग नहीं किया जाता।
  5. Python के reserved keywords को variable name के रूप में उपयोग नहीं करना चाहिए।
  6. Python variable names case-sensitive होते हैं।

Valid Variable Names के Examples

name = "Rahul"

age = 18

student_name = "Amit"

_marks = 90

total_marks = 450

student2 = "Ravi"

ऊपर दिए गए सभी examples Python में valid variable names के उदाहरण हैं।

Invalid Variable Names के Examples

2student = "Amit"

student name = "Ravi"

student-name = "Mohan"

इनमें समस्या इसलिए है क्योंकि variable naming rules का पालन नहीं किया गया है।

Variable का नाम Number से शुरू क्यों नहीं कर सकते?

Python में variable identifier की शुरुआत digit से नहीं की जा सकती।

गलत:

10marks = 90

सही:

marks10 = 90

इसलिए variable के नाम की शुरुआत letter या underscore से करें।

Python Variables Case-Sensitive होते हैं

Python में uppercase और lowercase letters अलग-अलग माने जाते हैं।

name = "Amit"
Name = "Ravi"

यहाँ name और Name दो अलग-अलग identifiers हैं।

Exam Tip: name, Name और NAME को Python में एक जैसा नहीं माना जाता।

Different Data Types के साथ Variables

Python में variables अलग-अलग प्रकार की values को refer कर सकते हैं।

student_name = "Rahul"
age = 18
height = 5.8
is_student = True
Variable Value Example Type
student_name "Rahul" String
age 18 Integer
height 5.8 Float
is_student True Boolean

Data Types को विस्तार से समझने के लिए हमारा अगला महत्वपूर्ण topic है:

Python Data Types in Hindi — int, float, string आदि

एक Variable की Value बदलना

Python में किसी variable को बाद में नई value assign की जा सकती है।

age = 18

age = 19

print(age)

Output:

19

नई assignment के बाद variable नई value को refer करता है।

Multiple Variables बनाना

Python में एक ही program में कई variables बनाए जा सकते हैं।

name = "Rahul"
age = 18
marks = 85

print(name)
print(age)
print(marks)

Output:

Rahul
18
85

एक साथ Multiple Variables में Values Assign करना

Python में कई variables को एक ही statement में values assign की जा सकती हैं।

x, y, z = 10, 20, 30

print(x)
print(y)
print(z)

Output:

10
20
30

एक ही Value को Multiple Variables में Assign करना

एक ही value को कई variables को assign किया जा सकता है।

a = b = c = 100

print(a)
print(b)
print(c)

Output:

100
100
100

Variable का Data Type कैसे Check करें?

Python में type() function का उपयोग किसी value या variable का type जानने के लिए किया जा सकता है।

age = 18

print(type(age))

Output में integer type दिखाई देगा।

एक और example:

name = "Rahul"

print(type(name))

इससे पता चलता है कि name में string value रखी गई है।

Variable और Constant में अंतर

Variable ऐसी value को refer कर सकता है जिसे program के दौरान बदला जा सकता है। Constant का उद्देश्य ऐसी value को represent करना होता है जिसे program में सामान्यतः बदला नहीं जाना चाहिए।

Python में constants के लिए अलग से कोई mandatory constant declaration syntax नहीं है। Python programming में constants के लिए सामान्यतः uppercase naming convention का उपयोग किया जाता है।

PI = 3.14159
MAX_MARKS = 100

Variable Name में Space की जगह क्या करें?

Variable name में space का उपयोग न करें। इसके स्थान पर underscore का उपयोग किया जा सकता है।

गलत:

student name = "Rahul"

सही:

student_name = "Rahul"

Python Variables के Common Mistakes

  • Variable name को number से शुरू करना।
  • Variable name में space का उपयोग करना।
  • Variable name में गलत special characters का उपयोग करना।
  • Case sensitivity को भूल जाना।
  • Python keywords को variable names की तरह उपयोग करना।
  • Variable को value assign किए बिना उसका उपयोग करने की कोशिश करना।

Python Variable का Practical Example

अब एक छोटा student information program देखते हैं।

name = "Rahul"
age = 18
marks = 85

print("Student Name:", name)
print("Age:", age)
print("Marks:", marks)

Output:

Student Name: Rahul
Age: 18
Marks: 85

RBSE Class 12 के लिए Important Questions

  1. Python variable क्या है?
  2. Python में variable कैसे बनाया जाता है?
  3. Python variable naming के कोई चार नियम लिखिए।
  4. Python में variable names case-sensitive क्यों होते हैं?
  5. Valid variable names के दो उदाहरण दीजिए।
  6. Invalid variable names के दो उदाहरण दीजिए।
  7. Python में assignment operator का क्या उपयोग है?
  8. type() function का उपयोग किसलिए किया जाता है?
  9. Multiple variables को एक statement में कैसे assign करते हैं?
  10. Python में variable की value कैसे बदली जाती है?

Quick Revision

Point Important Information
Variable Value को refer करने के लिए इस्तेमाल किया जाने वाला नाम
Assignment = operator से value assign की जाती है
First Character Letter या underscore से शुरू हो सकता है
Number Variable name की शुरुआत number से नहीं हो सकती
Space Variable name में space का उपयोग नहीं किया जाता
Case Sensitive name और Name अलग identifiers हैं
Type Check type() function

Frequently Asked Questions (FAQs)

Python Variable क्या है?

Python में variable किसी value को refer करने के लिए इस्तेमाल किया जाने वाला नाम है।

Python में variable कैसे बनाते हैं?

Variable को value assign करके बनाया जा सकता है। उदाहरण: age = 18

क्या Python में variable का data type पहले से बताना पड़ता है?

सामान्य assignment में Python में variable के लिए पहले से data type लिखना आवश्यक नहीं होता।

क्या Python variable names case-sensitive होते हैं?

हाँ। name और Name Python में अलग identifiers हैं।

Python में variable name number से शुरू हो सकता है?

नहीं। Variable name की शुरुआत digit से नहीं की जा सकती।

अब अगला Topic पढ़ें

RBSE Python Study Tip: Python सीखते समय केवल definitions याद न करें। प्रत्येक concept का छोटा program स्वयं लिखें, run करें और output को समझें। लगातार practice से programming concepts अधिक आसानी से समझ में आते हैं।