Important Notice:

The pass Statement

The pass Statement

25 views 2 min read

The pass Statement :-

pass Python का एक Loop Control Statement (लूप नियंत्रण कथन) है। इसका उपयोग तब किया जाता है जब किसी जगह कोई action नहीं करना हो, लेकिन Python के syntax के अनुसार वहाँ कोई statement लिखना जरूरी हो।

pass को execute करने पर Python कुछ नहीं करता और program की execution सामान्य रूप से आगे चलती रहती है।

English

The pass statement is a null statement in Python. It is used when we want to do nothing at a particular place in the program.

When Python executes pass, it does nothing and continues the program normally.

Syntax:-
 
pass
 
Example:-
 
for i in range(1, 6):

    if i == 3:
        pass

    print(i)
 
Output:-
1
2
3
4
5
 
Because:-

range(1, 6) → 1, 2, 3, 4, 5

i = 1 → pass execute नहीं होगा → 1 print होगा।
i = 2 → 2 print होगा।
i = 3 → condition True होगी → pass execute होगा।
pass कुछ नहीं करेगा।
इसके बाद print(i) execute होगा और 3 print होगा।
फिर 4 और 5 भी print होंगे।

इसलिए pass किसी value को skip नहीं करता।

English

When i = 3, the pass statement is executed. It does nothing, so the next statement, print(i), is still executed.

Therefore, 3 is also printed.

pass का Simple Example :-
if 10 > 5:
    pass

यहाँ condition True है, लेकिन pass के कारण कोई action नहीं किया जाएगा।

English:
The condition is True, but pass tells Python to do nothing.

pass in a Function :-

कभी-कभी हम function बनाना चाहते हैं लेकिन उसमें अभी कोई code नहीं लिखना चाहते। वहाँ pass का उपयोग किया जा सकता है।

Example:-
 
def my_function():
    pass

यह एक valid function है।

English:
This creates a valid function without writing any code inside it.

हिंदी:
यह एक valid function बनाता है, जिसमें अभी कोई कार्य नहीं किया गया है।

pass in a Class :-
 
class Student:
    pass

यहाँ Student नाम की एक empty class बनाई गई है।

English:
An empty Student class is created using pass.
 
pass का उपयोग( uses of pass):-
 
1. Empty Block बनाने के लिए
age=34
if age >= 18:
    pass

जब अभी कोई code नहीं लिखना हो।

2. Empty Function बनाने के लिए
 
def calculate():
    pass
 
3. Empty Class बनाने के लिए
class Employee:
    pass
 
4. Future Code के लिए Placeholder
for i in range(10):
    pass

बाद में इस loop के अंदर code लिखा जा सकता है।

Related Notes