Python If Else Statements - Conditional Statements Last Updated : 08 Mar, 2025 Comments Improve Suggest changes Like Article Like Report Try it on GfG Practice 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 evaluates to True, the block of code inside the if statement is executed.If StatementExample of If Statement: Python i = 10 # Checking if i is greater than 15 if (i > 15): print("10 is less than 15") print("I am Not in if") if....else Statementif...else statement is a control statement that helps in decision-making based on specific conditions. When the if condition is False. If the condition in the if statement is not true, the else block will be executed.If....else StatementLet's look at some examples of if-else statements.Simple if-else Python i = 20 # Checking if i is greater than 0 if (i > 0): print("i is positive") else: print("i is 0 or Negative") If Else in One-line If we need to execute a single statement inside the if or else block then one-line shorthand can be used. Python a = -2 # Ternary conditional to check if number is positive or negative res = "Positive" if a >= 0 else "Negative" print(res) OutputNegative Logical Operators with If..ElseWe can combine multiple conditions using logical operators such as and, or, and not. Python age = 25 exp = 10 # Using '>' operator & 'and' with if-else if age > 23 and exp > 8: print("Eligible.") else: print("Not eligible.") OutputEligible. Nested If Else StatementNested if...else statement occurs when if...else structure is placed inside another if or else block. Nested If..else allows the execution of specific code blocks based on a series of conditional checks. Nested if StatementExample of Nested If Else Statement: Python i = 10 if (i == 10): # First if statement if (i < 15): print("i is smaller than 15") # Nested - if statement # Will only be executed if statement above # it is true if (i < 12): print("i is smaller than 12 too") else: print("i is greater than 15") else: print("i is not equal to 10") if…elif…else Statementif-elif-else statement in Python is used for multi-way decision-making. This allows us to check multiple conditions sequentially and execute a specific block of code when a condition is True. If none of the conditions are true, the else block is executed.Example: Python i = 25 # Checking if i is equal to 10 if (i == 10): print("i is 10") # Checking if i is equal to 15 elif (i == 15): print("i is 15") # Checking if i is equal to 20 elif (i == 20): print("i is 20") # If none of the above conditions are true else: print("i is not present") Similar Reads:Python3 - if , if..else, Nested if, if-elif statementsUsing Else Conditional Statement With For loop in PythonHow to use if, else & elif in Python Lambda Functions Comment More infoAdvertise with us Next Article Python If Else Statements - Conditional Statements devanshuagarwal Follow Improve Article Tags : Misc Python python-basics python Practice Tags : Miscpythonpython Similar Reads Python - Output Formatting In Python, output formatting refers to the way data is presented when printed or logged. Proper formatting makes information more understandable and actionable. Python provides several ways to format strings effectively, ranging from old-style formatting to the newer f-string approach.Formatting Out 5 min read Python Operators In Python programming, Operators in general are used to perform operations on values and variables. These are standard symbols used for logical and arithmetic operations. In this article, we will look into different types of Python operators. OPERATORS: These are the special symbols. Eg- + , * , /, 6 min read Ternary Operator in Python The ternary operator in Python allows us to perform conditional checks and assign values or perform operations on a single line. It is also known as a conditional expression because it evaluates a condition and returns one value if the condition is True and another if it is False.Basic Example of Te 5 min read Operator Overloading in Python Operator Overloading means giving extended meaning beyond their predefined operational meaning. For example operator + is used to add two integers as well as join two strings and merge two lists. It is achievable because '+' operator is overloaded by int class and str class. You might have noticed t 8 min read Python | a += b is not always a = a + b In Python, a += b doesn't always behave the same way as a = a + b, the same operands may give different results under different conditions. But to understand why they show different behaviors you have to deep dive into the working of variables. before that, we will try to understand the difference b 4 min read Difference between == and is operator in Python In Python, == and is operators are both used for comparison but they serve different purposes. The == operator checks for equality of values which means it evaluates whether the values of two objects are the same. On the other hand, is operator checks for identity, meaning it determines whether two 4 min read Python | Set 3 (Strings, Lists, Tuples, Iterations) In the previous article, we read about the basics of Python. Now, we continue with some more python concepts. Strings in Python: A string is a sequence of characters that can be a combination of letters, numbers, and special characters. It can be declared in python by using single quotes, double quo 3 min read Python String A string is a sequence of characters. Python treats anything inside quotes as a string. This includes letters, numbers, and symbols. Python has no character data type so single character is a string of length 1.Pythons = "GfG" print(s[1]) # access 2nd char s1 = s + s[0] # update print(s1) # printOut 6 min read Python Lists In Python, a list is a built-in dynamic sized array (automatically grows and shrinks). We can store all types of items (including another list) in a list. A list may contain mixed type of items, this is possible because a list mainly stores references at contiguous locations and actual items maybe s 6 min read Python Tuples A tuple in Python is an immutable ordered collection of elements. Tuples are similar to lists, but unlike lists, they cannot be changed after their creation (i.e., they are immutable). Tuples can hold elements of different data types. The main characteristics of tuples are being ordered , heterogene 6 min read Like