Seedha content par jao
🤖 Python Hindi Bot
Namaste! Main Python Hindi Bot hoon 🐍
Python ya AI se related kuch bhi type karke pucho, ya neeche se quick sawaal chuno.
WhatsApp

Stay Connected with PythonHindii

Join our WhatsApp Community to get the latest Python tutorials, coding tips, interview questions, project updates, and learning resources directly on your phone.

Join WhatsApp Community
⇧
Python Hindi Logo
Python in Hindi | Programming Education
🎓 100% Free · Hindi me · Beginner se Career tak

Python Tutorial in HindiiLearn Python Programming for Free

Python, AI, Data Analytics aur SQL ek hi jagah, simple Hindi me. Padho, browser me code chalao, projects banao aur career shuru karo.

main.py
# Python seekho, Hindi me naam = "Ravi" for i in range(3): print("Namaste", naam)
▸ python main.py
🐍 Python 🤖 AI & ML 📊 Data 🗄️ SQL

Chahe Student ho ya Professional, yahan aapke liye sab hai

Apna card chuno, seedha sahi jagah pahunch jaoge.

🎓

Student ho?

School ya college me ho? Python zero se seekho, notes aur cheat sheets ke saath.

  • Python basics se OOP tak
  • Notes, PDFs aur Cheat Sheets
  • Browser me practice, kuch install nahi
💼

Working Professional ho?

Kaam ke saath nayi skill jodo: data, SQL aur AI se apna kaam tez karo.

  • Pandas, NumPy, Excel, Power BI
  • SQL aur MySQL databases
  • Automation aur AI Tools
🚀

Job ya Career change?

Projects banao, interview ki taiyari karo aur sahi roadmap follow karo.

  • Real projects, portfolio ke liye
  • Python aur SQL interview questions
  • AI Engineer, Data Scientist roadmap

Python Hindii Kaise Kaam Karta Hai?

Ek hi jagah 4 layers: seekho, practice karo, skills banao aur career shuru karo. Har layer ek step hai, us par click karke seedha wahan pahuncho. Computer par drag karke 3D me ghumao bhi.

Layer 1 · Seekho

Python Basics se Advanced tak

Variables, loops, functions se OOP tak, sab simple Hindi me. Yahin se shuru karo.

Naye ho? 3 step me shuru karo

💻 Online Code Editor

Browser me hi code likho aur turant chalao

Koi software install nahi. Code likho, Run dabao aur result usi waqt dekho.

  • Python, Java, C, C++, JavaScript, HTML aur aur bhi languages
  • input(), graphs aur multi-file HTML project bhi chalte hain
  • Mobile aur computer, dono par chalta hai
main.py
naam = input("Naam batao: ") for i in range(3): print("Namaste", naam)
▸ python main.py
PythonJavaCC++JavaScriptHTML

Python se AI tak ka poora rasta

8 steps, ek ke baad ek. Aage-peeche ghumao aur apni stage se seedha shuru karo.

Step 1 🐍

Python Basics

IntroductionVariablesData TypesOperatorsInput & OutputConditionsLoops
Start Python →
Step 2 💻

Python Intermediate

ListsTuplesSetsDictionariesStringsModulesFile Handling
Continue Python →
Step 4 🗄️

SQL & Databases

SQL BasicsMySQLSELECTINSERTUPDATEDELETEJOIN
Learn SQL →
Step 5 📊

Data Analytics

NumPyPandasData CleaningData VisualizationMatplotlibExploratory Data Analysis
Learn Data Analytics →
Step 6 🤖

Machine Learning

ML BasicsSupervised & Unsupervised LearningRegressionClassificationModel EvaluationScikit-learn
Learn Machine Learning →
Step 7 🧠

Artificial Intelligence

AI FundamentalsGenerative AIAI ToolsPrompt EngineeringLLM ConceptsAI Automation
Explore AI →
Step 8 🚀

Projects & Career

Python ProjectsAI ProjectsData ProjectsPortfolioGitHubInterview PreparationCareer Roadmap
Build Your Career →
Step 1 / 8

Python While Loop in Hindi – Syntax, Examples & Loop में User Input

While Loop का Syntax

Python While Loop in Hindi – Syntax, Examples, Flowchart और Practice Programs

                तो loops का topic आते ही थोड़ा confusion हो जाता है — क्योंकि loops बहुत बार use होते हैं, लेकिन शुरुआत में इनकी working समझना थोड़ा tricky लगता है। अगर आपने अभी तक हमारा Python Tutorial in Hindi नहीं पढ़ा है, तो पहले वहाँ से basics clear कर लें, फिर यह post और भी आसानी से समझ आएगा।

Python While Loop एक ऐसा looping statement है, जिसका इस्तेमाल किसी code block को तब तक बार-बार execute करने के लिए किया जाता है, जब तक दी गई condition True रहती है। अगर आपको पहले से पता नहीं है कि loop कितनी बार चलेगा, या loop किसी condition पर depend करता है, तो while loop ही सही choice होता है।

Python While Loop क्या है?

The while loop in Python is used to execute a block of code as long as a specified condition remains True. It checks the condition before each iteration and continues to execute the code block until the condition evaluates to False.

Example
count = 1
while count <= 5:
print(count)
count += 1

यहाँ condition count <= 5 को प्रत्येक iteration से पहले evaluate किया जाता है। अगर condition True होती है, तो code block execute होता है। अगर condition False हो जाती है, तो loop terminate हो जाता है और program loop के बाद वाले next statement के साथ continue करता है।


 While Loop का Syntax

while condition:
    # code to be executed

यहाँ:

  • while Python का keyword है। अगर आप Python के सारे keywords के बारे में detail में जानना चाहते हैं, तो Python Keywords in Hindi वाला guide जरूर देखें।
  • condition वह expression है, जिसे Python हर बार check करता है।
  • condition True होने पर loop का code execute होता है।
  • condition False होने पर loop समाप्त हो जाता है।
  • Python में indentation बहुत important है — बिना सही indentation के program error देगा।

While Loop कैसे काम करता है?

While loop की working को इन steps से समझ सकते हैं:

  1. सबसे पहले condition check होती है।
  2. अगर condition True है, तो loop के अंदर का code execute होता है।
  3. फिर condition दोबारा check होती है।
  4. यह process तब तक repeat होता है, जब तक condition True रहती है।
  5. जैसे ही condition False होती है, loop terminate हो जाता है।

एक example से देखते हैं:

count = 1

while count <= 3:
    print(count)
    count += 1

इसमें step by step क्या हो रहा है:

  • पहले count = 1 set होता है।
  • 1 <= 3 → True, तो 1 print होगा।
  • count बढ़कर 2 हो जाएगा।
  • 2 <= 3 → True, तो 2 print होगा।
  • count बढ़कर 3 हो जाएगा।
  • 3 <= 3 → True, तो 3 print होगा।
  • count बढ़कर 4 हो जाएगा।
  • 4 <= 3 → False, इसलिए loop यहीं रुक जाएगा।

याद रखने वाली बात: हर iteration के बाद condition को दोबारा check करना ही while loop का core logic है।


Python While Loop का Simple Example

number = 1

while number <= 5:
    print("Python")
    number += 1

Output:

Python
Python
Python
Python
Python

यहाँ "Python" पाँच बार print होगा, क्योंकि condition पाँच iterations तक True रहती है।


While Loop में Counter का Use

While loop में counter variable का इस्तेमाल बहुत common है, क्योंकि इसी से हम decide करते हैं कि loop कब तक चलेगा।

count = 1

while count <= 10:
    print(count)
    count += 1

Output:

1
2
3
4
5
6
7
8
9
10

यहाँ count += 1 हर iteration के बाद counter की value को एक से बढ़ाता है।


While Loop से Reverse Counting

While loop का इस्तेमाल reverse counting के लिए भी किया जा सकता है।

count = 5

while count >= 1:
    print(count)
    count -= 1

Output:

5
4
3
2
1

यहाँ count -= 1 हर iteration के बाद value को एक से कम करता है।


Python While Loop में User Input

While loop का इस्तेमाल user से input लेकर भी किया जा सकता है, जिससे program interactive बन जाता है।

number = int(input("Enter a number: "))

while number <= 5:
    print(number)
    number += 1

इस program में user द्वारा दिए गए number से counting शुरू होगी और 5 तक चलेगी।


 While Loop से 1 से 10 तक Sum

While loop का इस्तेमाल numbers का sum निकालने के लिए भी किया जा सकता है।

number = 1
total = 0

while number <= 10:
    total += number
    number += 1

print("Total:", total)

Output:

Total: 55

इस program में 1 से 10 तक सभी numbers को जोड़कर total variable में store किया जाता है।


 While Loop में Even Numbers

While loop से 1 से 10 तक even numbers print कर सकते हैं।

number = 1

while number <= 10:
    if number % 2 == 0:
        print(number)
    number += 1

Output:

2
4
6
8
10

यहाँ % operator का इस्तेमाल यह check करने के लिए किया गया है कि number 2 से completely divisible है या नहीं।


 While Loop में Odd Numbers

इसी तरह odd numbers भी print किए जा सकते हैं:

number = 1

while number <= 10:
    if number % 2 != 0:
        print(number)
    number += 1

Output:

1
3
5
7
9

 While Loop With Break

break statement का इस्तेमाल loop को तुरंत terminate करने के लिए किया जाता है — चाहे condition अभी भी True क्यों न हो।

count = 1

while count <= 10:
    if count == 6:
        break

    print(count)
    count += 1

Output:

1
2
3
4
5

जब count == 6 होता है, तब break loop को तुरंत खत्म कर देता है।


 While Loop With Continue

continue statement current iteration को skip करके सीधा अगली iteration पर चला जाता है।

count = 0

while count < 5:
    count += 1

    if count == 3:
        continue

    print(count)

Output:

1
2
4
5

इस example में 3 को skip कर दिया जाता है, और बाकी numbers normally print होते हैं।


Infinite While Loop

अगर while loop की condition हमेशा True रहती है, तो loop कभी खत्म नहीं होगा। इसे Infinite Loop कहते हैं।

while True:
    print("Hello Python")

यह program लगातार "Hello Python" print करता रहेगा, जब तक आप manually program stop न करें।

Infinite loop को control में रखने के लिए break का इस्तेमाल किया जा सकता है:

while True:
    number = int(input("Enter 0 to stop: "))

    if number == 0:
        break

    print("You entered:", number)

यह program तब तक चलता रहेगा जब तक user 0 enter नहीं करता।


While Loop में Infinite Loop से कैसे बचें?

While loop लिखते समय यह सुनिश्चित करें कि condition किसी point पर False हो जाए, वरना program hang हो सकता है।

गलत example:

count = 1

while count <= 5:
    print(count)

इस program में count की value कभी change नहीं होगी। इसलिए condition हमेशा True रहेगी और loop infinite बन जाएगा।

सही तरीका:

count = 1

while count <= 5:
    print(count)
    count += 1

यहाँ count लगातार बढ़ता है, इसलिए एक point आने पर condition False हो जाती है और loop सही तरह खत्म होता है।


 While Loop और For Loop में अंतर

Python में while और for दोनों ही loops हैं, लेकिन इनके इस्तेमाल का तरीका अलग होता है।

While Loop For Loop
Condition के आधार पर चलता है Sequence या iterable पर iterate करता है
Iterations की संख्या पहले से fix होना जरूरी नहीं जब sequence की length पता हो तब convenient है
User input और condition-based programs में useful List, tuple, string आदि पर iteration के लिए useful
Condition manually manage करनी पड़ सकती है Iteration automatically manage होता है

While Loop:

count = 1

while count <= 5:
    print(count)
    count += 1

For Loop:

for count in range(1, 6):
    print(count)

दोनों programs 1 से 5 तक numbers print करेंगे, बस approach अलग है।


While Loop में Indentation

Python में indentation बहुत important है, और while loop भी इससे exempt नहीं है।

सही:

count = 1

while count <= 5:
    print(count)
    count += 1

गलत:

count = 1

while count <= 5:
print(count)

इसलिए while loop के अंदर लिखे statements को proper indentation देना जरूरी है, वरना Python IndentationError दे देगा।


Practical Example: Password Attempts

While loop का इस्तेमाल limited attempts वाले programs में काफी किया जाता है — जैसे login systems।

password = ""

attempts = 0

while password != "python123" and attempts < 3:
    password = input("Enter password: ")
    attempts += 1

if password == "python123":
    print("Login successful")
else:
    print("Too many attempts")

यह example दिखाता है कि condition-based situations में while loop कितना useful हो सकता है।


Practical Example: Number Guessing

While loop का इस्तेमाल एक simple number guessing program बनाने में भी किया जा सकता है।

secret_number = 7
guess = 0

while guess != secret_number:
    guess = int(input("Guess the number: "))

print("Correct! You guessed the number.")

जब तक user सही number enter नहीं करता, loop चलता रहेगा।


 While Loop के Important Points

  • while loop एक condition-based loop है।
  • condition True होने पर loop execute होता है।
  • condition False होने पर loop समाप्त हो जाता है।
  • loop variable को update करना जरूरी हो सकता है, वरना infinite loop बन सकता है।
  • break loop को तुरंत terminate करता है।
  • continue current iteration को skip करता है।
  • गलत condition से infinite loop बन सकता है।
  • Python में indentation का सही होना जरूरी है।

अगर आप loops के साथ-साथ databases भी सीखना चाहते हैं, तो MySQL Tutorial in Hindi और Database Introduction in Hindi वाले articles भी काफी useful रहेंगे।


  FAQ

1. Python में While Loop क्या है?

Python में while loop एक looping statement है, जिसका इस्तेमाल किसी code block को तब तक execute करने के लिए किया जाता है, जब तक दी गई condition True रहती है।

2. Python While Loop का Syntax क्या है?

while condition:
    # code

3. While Loop कब समाप्त होता है?

जब while loop की condition False हो जाती है, तब loop terminate हो जाता है।

4. Python While Loop में Break क्या करता है?

break statement loop को तुरंत terminate कर देता है, चाहे condition अभी True ही क्यों न हो।

5. While Loop में Continue क्या करता है?

continue current iteration को skip करके loop की अगली iteration शुरू करता है।

6. Python में Infinite Loop क्या है?

जब loop की condition हमेशा True रहती है और loop समाप्त नहीं होता, तो उसे infinite loop कहते हैं।

while True:
    print("Python")

7. While Loop में Counter क्यों इस्तेमाल किया जाता है?

Counter का इस्तेमाल loop की iterations को control करने और condition को eventually False बनाने के लिए किया जाता है।

8. While Loop और For Loop में क्या अंतर है?

while loop मुख्य रूप से condition के आधार पर चलता है, जबकि for loop किसी sequence या iterable के elements पर iterate करने के लिए commonly इस्तेमाल होता है।

9. क्या While Loop के अंदर If Statement का इस्तेमाल कर सकते हैं?

हाँ। while loop के अंदर if, elif और else statements का इस्तेमाल किया जा सकता है।

10. क्या Python While Loop में User Input लिया जा सकता है?

हाँ। User input के आधार पर condition check करके while loop का इस्तेमाल interactive programs बनाने में किया जा सकता है।


Conclusion

Python का While Loop condition-based programming के लिए एक बहुत ही useful looping statement है। इसकी मदद से हम किसी code को तब तक execute कर सकते हैं, जब तक कोई condition True रहती है।

अगर आप Python सीखना शुरू कर रहे हैं, तो while, for, break और continue को अच्छे से समझना जरूरी है, क्योंकि real-world Python programs में इनका बहुत ज्यादा इस्तेमाल होता है। अगले step में आप Python For Loop, range() function और nested loops सीख सकते हैं।


Related Posts

🧑‍💻 Python Coding Lab

Python code likho, run karo aur practice karo — directly browser mein.