Important Notice:

Statements in Python

Statements in Python

5 views 2 min read

Statements in Python (पायथन में स्टेटमेंट्स) :-

Statement (स्टेटमेंट) वह निर्देश (Instruction) होता है जिसे Python Interpreter पढ़कर Execute (निष्पादित) करता है।
दूसरे शब्दों में, Python Program में लिखा गया प्रत्येक ऐसा Code जो कोई कार्य करता है, उसे Statement कहा जाता है।

एक Python Program कई Statements का समूह होता है। Interpreter इन Statements को एक-एक करके पढ़ता है और उनके अनुसार कार्य करता है।

English

A Statement is an instruction that the Python interpreter reads and executes.

In other words, any line of code that performs an action in a Python program is called a statement.

A Python program consists of one or more statements. The Python interpreter executes these statements one by one.

Example (उदाहरण) :-

print("Hello")
x = 10
y = 20
print(x + y)
 
Output-
Hello
30
Types of Statements (स्टेटमेंट्स के प्रकार) :-

Python में मुख्य रूप से निम्न प्रकार के Statements होते हैं—

  1. Simple Statements (सरल स्टेटमेंट)
  2. Compound Statements (कम्पाउंड स्टेटमेंट)

Compound Statements के अंतर्गत कई प्रकार के Statements आते हैं।

1. Simple Statement (सरल स्टेटमेंट) :-

जो Statement केवल एक कार्य करता है और सामान्यतः एक ही लाइन में लिखा जाता है, उसे Simple Statement कहते हैं।

English

A statement that performs a single task and is usually written in one line is called a Simple Statement.

Example
x = 10
print(x)
 
2. Compound Statement (कम्पाउंड स्टेटमेंट) :-

जो Statement एक Header (:) तथा उसके नीचे Indented Code Block रखता है, उसे Compound Statement कहते हैं।

English

A statement that contains a header ending with a colon (:) followed by an indented code block is called a Compound Statement.

Example
x=5
if x > 0:
    print("Positive")

 Output-

Positive

Types of Compound Statements (कम्पाउंड स्टेटमेंट के प्रकार) :-

1. Selection Statements

2. Iteration Statements

3. Jump Statements

4. Exception Handling Statements

1. Selection Statements (चयन स्टेटमेंट) -

Condition के आधार पर निर्णय लेने वाले Statements को Selection Statements कहते हैं।

English

Statements that make decisions based on a condition are called Selection Statements.

Includes (शामिल हैं)
  • if
  • if...else
  • if...elif...else
  • match...case (Python 3.10+)
Example
age = 18
if age >= 18:
    print("Eligible")
else:
    print("Not Eligible")
 
2. Iteration Statements (पुनरावृत्ति स्टेटमेंट) :-

जो Statements किसी Code को बार-बार Execute करते हैं उन्हें Iteration Statements कहते हैं।

English

Statements that execute a block of code repeatedly are called Iteration Statements.

Includes
  • for
  • while

Example -

for i in range(5):
    print(i)
Output-
0 1 2 3 4
3. Jump Statements (जंप स्टेटमेंट) -

जो Statements Program के Flow को बदलते हैं उन्हें Jump Statements कहते हैं।

English

Statements that change the normal flow of program execution are called Jump Statements.

Includes
  • break
  • continue
  • pass
  • return
Example -
for i in range(5):
    if i == 3:
        break
    print(i)
Output-
0 1 2 
4. Exception Handling Statements (अपवाद प्रबंधन स्टेटमेंट)  -

Program में आने वाली Errors को संभालने वाले Statements को Exception Handling Statements कहते हैं।

English

Statements used to handle runtime errors are called Exception Handling Statements.

Includes
  • try
  • except
  • else
  • finally
  • raise

Example -

try:
    print(10/0)
except ZeroDivisionError:
    print("Cannot divide by zero")
 
Output-
Cannot divide by zero
 

Related Notes