Python Program to Maximum of two numbers

Find greatest of two numbers in python if statement

1num1 = 10 2num2 = 20 3 4if num1>num2: 5 print(f"{num1} is greater") 6else: 7 print(f"{num2} is greater")

Output

120 is greater

Find maximum of two numbers using Ternary Operator

1num1 = 50 2num2 = 20 3 4mx = num1 if num1>num2 else num2 5print("{} is greater".format(mx))

Output

150 is greater

Find maximum of two numbers using Python Max Method

1num1 = 50 2num2 = 20 3 4print("{} is greater".format(max(num1, num2)))

Output

150 is greater

Find maximum of two numbers using Lambda function

1num1 = 50 2num2 = 20 3 4findMax = lambda i, j : i if i>j else j 5print("{} is greater".format(findMax(num1, num2)))

Output

150 is greater