Check multiple conditions in if statement - Python Last Updated : 02 Aug, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report If-else conditional statement is used in Python when a situation leads to two conditions and one of them should hold true. Syntax:if (condition): code1else: code2[on_true] if [expression] else [on_false]Note: For more information, refer to Decision Making in Python (if , if..else, Nested if, if-elif)Multiple conditions in if statement Here we'll study how can we check multiple conditions in a single if statement. This can be done by using 'and' or 'or' or BOTH in a single statement. Syntax:if (cond1 AND/OR COND2) AND/OR (cond3 AND/OR cond4): code1else: code2and comparison = for this to work normally both conditions provided with should be true. If the first condition falls false, the compiler doesn't check the second one. If the first condition is true and the compiler moves to the second and if the second comes out to be false, false is returned to the if statement. or Comparison = for this to work normally either condition needs to be true. The compiler checks the first condition first and if that turns out to be true, the compiler runs the assigned code and the second condition is not evaluated. If the first condition turns out to be false, the compiler checks the second, if that is true the assigned code runs but if that fails too, false is returned to the if statement. The following examples will help understand this better: PROGRAM 1: program that grants access only to kids aged between 8-12 Python3 1== age = 18 if ((age>= 8) and (age<= 12)): print("YOU ARE ALLOWED. WELCOME !") else: print("SORRY ! YOU ARE NOT ALLOWED. BYE !") Output:SORRY ! YOU ARE NOT ALLOWED. BYE !PROGRAM 2: program that checks the agreement of the user to the terms Python3 1== var = 'N' if (var =='Y' or var =='y'): print("YOU SAID YES") elif(var =='N' or var =='n'): print("YOU SAID NO") else: print("INVALID INPUT") Output:YOU SAID NOPROGRAM 3: program to compare the entered three numbers Python3 1== a = 7 b = 9 c = 3 if((a>b and a>c) and (a != b and a != c)): print(a, " is the largest") elif((b>a and b>c) and (b != a and b != c)): print(b, " is the largest") elif((c>a and c>b) and (c != a and c != b)): print(c, " is the largest") else: print("entered numbers are equal") Output:9 is the largest Not just two conditions we can check more than that by using 'and' and 'or'. PROGRAM 4: Python3 1== a = 1 b = 1 c = 1 if(a == 1 and b == 1 and c == 1): print("working") else: print("stopped") Output:working Comment More infoAdvertise with us Next Article Using Else Conditional Statement With For loop in Python V vanshikagoyal43 Follow Improve Article Tags : Python python-basics Practice Tags : python Similar Reads Conditional Statements in Python Conditional statements in Python are used to execute certain blocks of code based on specific conditions. These statements help control the flow of a program, making it behave differently in different situations.If Conditional Statement in PythonIf statement is the simplest form of a conditional sta 6 min read Using Else Conditional Statement With For loop in Python Using else conditional statement with for loop in python In most of the programming languages (C/C++, Java, etc), the use of else statement has been restricted with the if conditional statements. But Python also allows us to use the else condition with for loops. The else block just after for/while 2 min read Check if String Contains Substring in Python This article will cover how to check if a Python string contains another string or a substring in Python. Given two strings, check whether a substring is in the given string. Input: Substring = "geeks" String="geeks for geeks"Output: yesInput: Substring = "geek" String="geeks for geeks"Output: yesEx 8 min read Nested-if statement in Python For more complex decision trees, Python allows for nested if statements where one if statement is placed inside another. This article will explore the concept of nested if statements in Python, providing clarity on how to use them effectively.Python Nested if StatementA nested if statement in Python 2 min read Python If Else Statements - Conditional Statements In Python, If-Else is a fundamental conditional statement used for decision-making in programming. If...Else statement allows to execution of specific blocks of code depending on the condition is True or False.if Statementif statement is the most simple decision-making statement. If the condition ev 4 min read Python - if , if..else, Nested if, if-elif statements There are situations in real life when we need to do some specific task and based on some specific conditions, we decide what we should do next. Similarly, there comes a situation in programming where a specific task is to be performed if a specific condition is True. In such cases, conditional stat 7 min read Like