Online Computer Courses Classes and Training Program

Python Variables और Data Types in Hindi | Complete Beginner Guide

Python Variables in Hindi


Python Variables, Data Types और Memory को आसान उदाहरणों के साथ समझें | Complete Python Tutorial in Hindi – Part 3



Introduction

अब तक आपने सीखा कि Python क्या है, इसे अपने कंप्यूटर में कैसे Install करना है और पहला Program कैसे लिखना है।

अब Programming का सबसे महत्वपूर्ण Concept शुरू होता है—Variables

यदि Variables समझ आ गए, तो Programming की आधी Foundation मजबूत हो जाती है।

इस अध्याय में हम सीखेंगे—

  • Variable क्या होता है?

  • Variable क्यों जरूरी है?

  • Memory कैसे काम करती है?

  • Data Types क्या होते हैं?

  • String, Integer, Float, Boolean और None

  • Variable Naming Rules

  • Best Practices

  • Practical Programs


Variable क्या होता है?

Variable एक ऐसा नाम (Name) होता है जिसके अंदर हम किसी Value को Store करते हैं।

सरल शब्दों में—

Variable = Value रखने का नामित डिब्बा (Named Container)

उदाहरण:

name = "Ajay Kumar Paswan"

यहाँ

  • name → Variable

  • "Ajay Kumar Paswan" → Value


Variable की आवश्यकता क्यों होती है?

मान लीजिए आपके स्कूल में 1000 छात्रों के नाम हैं।

यदि हर जगह पूरा नाम बार-बार लिखना पड़े, तो काम कठिन हो जाएगा।

इसके बजाय हम एक Variable बना सकते हैं।

student_name = "Rahul"

अब जहाँ भी छात्र का नाम चाहिए—

print(student_name)

Output

Rahul

यदि बाद में नाम बदलना हो—

student_name = "Aman"

बाकी Program में कुछ बदलने की आवश्यकता नहीं होगी।


Memory कैसे काम करती है?

जब आप Variable बनाते हैं—

age = 20

Python Computer की Memory में एक स्थान (Memory Location) बनाता है।

उस स्थान पर Value Store होती है।

Memory

+------------+
| age = 20   |
+------------+

जब Program लिखता है—

print(age)

Python Memory से Value पढ़कर Output देता है।

20

पहला Variable Program

name = "Ajay"

print(name)

Output

Ajay

कई Variables बनाना

name = "Ajay"

age = 22

city = "Nalanda"

print(name)

print(age)

print(city)

Output

Ajay

22

Nalanda

Variable की Value बदलना

Variable की सबसे बड़ी विशेषता है—

इसकी Value बदली जा सकती है।

age = 22

print(age)

age = 23

print(age)

Output

22

23

Variable Assignment

Python में

=

का अर्थ Mathematics जैसा "बराबर" नहीं होता।

यह Assignment Operator है।

उदाहरण—

salary = 30000

इसका अर्थ है—

30000 को Variable salary में Store करो।


Data Type क्या होता है?

हर Variable किसी न किसी प्रकार का Data Store करता है।

उदाहरण—

नाम

उम्र

Salary

True/False

इन सभी का प्रकार अलग होता है।

इसी प्रकार को Data Type कहते हैं।


Python के मुख्य Data Types

Python में कई Data Types होते हैं।

लेकिन शुरुआत में पाँच सबसे महत्वपूर्ण Types सीखना पर्याप्त है।

  • Integer

  • Float

  • String

  • Boolean

  • None


Integer (int)

Integer पूर्ण संख्या होती है।

उदाहरण

age = 22

marks = 95

temperature = -5

सभी Integer हैं।


Float (float)

Decimal वाली संख्या Float कहलाती है।

price = 99.99

height = 5.8

pi = 3.14159

String (str)

Text को String कहते हैं।

name = "Ajay"

country = "India"

course = "Python"

String हमेशा Quotes में लिखी जाती है।


Quotes कितने प्रकार के होते हैं?

Python में String तीन तरीकों से लिखी जा सकती है।

Double Quotes

name = "Ajay"

Single Quotes

name = 'Ajay'

Triple Quotes

message = """Welcome to Python"""

Boolean (bool)

Boolean केवल दो Values रखता है।

True

False

उदाहरण

is_student = True

is_married = False

ध्यान दें—

सही लिखावट

True

False

गलत

true

false

None Data Type

यदि किसी Variable में अभी कोई Value नहीं रखनी है—

data = None

इसका अर्थ है—

अभी Variable खाली है।


type() Function

किसी Variable का Data Type जानने के लिए

type()

का उपयोग किया जाता है।

उदाहरण

name = "Ajay"

print(type(name))

Output

<class 'str'>

Integer

age = 22

print(type(age))

Output

<class 'int'>

Float

price = 199.99

print(type(price))

Output

<class 'float'>

Boolean

student = True

print(type(student))

Output

<class 'bool'>

None

data = None

print(type(data))

Output

<class 'NoneType'>

Variable Naming Rules

Python में Variable का नाम रखने के कुछ नियम हैं।

Rule 1

नाम Letter या Underscore से शुरू होना चाहिए।

सही

student

_age

courseName

गलत

1student

Rule 2

Special Characters का उपयोग नहीं कर सकते।

गलत

price#

student@

Rule 3

Python Keywords का उपयोग Variable Name के रूप में नहीं कर सकते।

गलत

True = 5

False = 10

None = 20

अच्छे Variable Name कैसे रखें?

गलत

x

y

abc

aaa

सही

student_name

total_marks

employee_salary

course_fee

Variable Name देखकर ही उसका अर्थ समझ आ जाना चाहिए।


Case Sensitive Language

Python Case Sensitive Language है।

इसका अर्थ—

Age

और

age

दो अलग-अलग Variables हैं।


Practical Example

name = "Ajay Kumar Paswan"

age = 22

course = "Python"

price = 999.99

print("Student Name :", name)

print("Age :", age)

print("Course :", course)

print("Course Fee :", price)

Output

Student Name : Ajay Kumar Paswan

Age : 22

Course : Python

Course Fee : 999.99

Real Life Example

ATM Card Number

Bank Balance

Mobile Number

Student Name

इन सभी को Program में Variables की सहायता से Store किया जाता है।


Common Mistakes

❌ Quotes भूल जाना

name = Ajay

name = "Ajay"

2name = "Ajay"

name2 = "Ajay"

True = 50

यह Error देगा।


Practice Programs

Program 1

अपना नाम Variable में Store करके Print करें।


Program 2

अपनी उम्र Variable में Store करें।


Program 3

अपने शहर का नाम Print करें।


Program 4

अपनी Height Float में Store करें।


Program 5

Boolean Variable बनाकर Print करें।


Program 6

एक Variable में None Store करें।


Program 7

पाँच अलग-अलग Data Types के Variables बनाइए और type() से उनका प्रकार पता लगाइए।


Interview Questions

Variable क्या होता है?

Data Type क्या होता है?

Integer और Float में क्या अंतर है?

String कैसे लिखी जाती है?

Boolean में कितनी Values होती हैं?

None का क्या उपयोग है?

type() Function क्या करता है?

Python Case Sensitive Language क्यों कहलाती है?


Chapter Summary

इस अध्याय में आपने सीखा—

  • Variable क्या है

  • Variable Memory में कैसे Store होता है

  • Assignment Operator

  • Integer

  • Float

  • String

  • Boolean

  • None

  • type() Function

  • Variable Naming Rules

  • Case Sensitivity

  • Best Practices

  • Practical Examples

  • Practice Programs

अब आपके पास Python की सबसे महत्वपूर्ण Foundation तैयार हो चुकी है। आगे आने वाले अध्यायों में यही Variables Input, Operators, Conditions, Loops और Functions के साथ मिलकर वास्तविक Programs बनाने में उपयोग होंगे।


अगले अध्याय में क्या सीखेंगे?

Part 4 – Python Input Function (input()), User से Data लेना, Type Conversion (int(), float(), str()) और पहला Interactive Program बनाना।


Post a Comment

0 Comments