t()
rin i ni t __
p __
pa
type() ss
Conditional statement
which evaluates actions in the program and evaluates if it's true or false.
06
Conditional statement in python
Conditional statements are used through the various programming
languages to instruct the computer on the decision to make when given
some conditions.
सशतर्त कथनों का उपयोग व भन्न प्रोग्रा मंग भाषाओं के माध्यम से कंप्यूटर को कुछ शतर्तें
दए जाने पर नणर्तय लेने का नदर्दे श दे ने के लए कया जाता है ।
Conditional statement in python
if statement.
if-else statement.
if-elif-else statement.
if statement
The if statement is the most simple decision-making statement. It is used to decide
whether a certain statement or block of statements will be executed or not.
य द कथन सबसे सरल नणर्तय लेने वाला कथन है । इसका उपयोग यह तय करने के लए कया जाता है
क कसी नि चत कथन या कथनों के ब्लॉक को नष्पा दत कया जाएगा या नहीं।
syntax :
if condition:
statement1
Example :
i = 10
if (i > 15):
print("10 is less than 15")
if-else statement
The if statement alone tells us that if a condition is true it will execute a block of statements and if
the condition is false it won’t. But if we want to do something else if the condition is false, we can
use the else statement with if statement to execute a block of code when the if condition is false.
य द कथन अकेले हमें बताता है क य द कोई शतर्त सत्य है तो यह कथनों के एक ब्लॉक को नष्पा दत करे गा और य द
िस्थ त गलत है तो यह नहीं करे गा। ले कन य द िस्थ त गलत होने पर हम कुछ और करना चाहते हैं, तो य द िस्थ त
गलत होने पर हम कोड के एक ब्लॉक को नष्पा दत करने के लए if स्टे टमें ट के साथ अन्य स्टे टमें ट का उपयोग कर
सकते हैं।
if (condition):
# Executes this block if
else:
# Executes this block if
if-elif-else statement
The if statements are executed from the top down. As soon as one of
the conditions controlling the if is true, the statement associated with
that if is executed, and the rest of the ladder is bypassed. If none of
the conditions is true, then the final else statement will be executed.
if कथनों को ऊपर से नीचे तक क्रियािन्वत कया जाता है । जैसे ही य द को नयं त्रित
करने वाली शतर्तों में से एक सत्य है , तो उससे जुड़ा कथन नष्पा दत कया जाता है ,
और शेष सीढ़ी को बायपास कर दया जाता है । य द कोई भी शतर्त सत्य नहीं है , तो
अं तम अन्यथा कथन नष्पा दत कया जाएगा।
Syntax of if-elif-if statement
if (condition):
statement
elif (condition):
statement
.
.
else:
statement