×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python if, if...else Statement Examples

The if, if...else statement examples: Here, we will learn about simple if else by using some of the small example codes. By Pankaj Singh Last updated : April 09, 2023

Example 1: Check whether a given number is 10 or not

a=int(input("Enter A : "))

if a==10:
    print("Equal to 10")
else:
    print("Not Equal to 10")

Output

Enter A : 10
Equal to 10

Example 2: Find largest of two numbers

a=int(input("Enter A: "))
b=int(input("Enter B: "))

if a>b:
    g=a
else:
    g=b

print("Greater = ",g)

Output

Enter A: 36
Enter B: 24
Greater =  36

Example 3: Find largest of two numbers using single statement

a=int(input("Enter A: "))
b=int(input("Enter B: "))

c= a if a>b else b

print("Greater = ",c)

Output

Enter A: 24
Enter B: 36
Greater =  36

Python Basic Programs »

Advertisement
Advertisement

Related Programs

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.