# Maximum of two numbers in Python

## Maximum of two numbers in Python

Given two numbers, write a Python code to find the Maximum of these two numbers.
Examples:

```Input: a = 2, b = 4
Output: 4

Input: a = -1, b = -4
Output: -1```

Method #1: This is the naive approach where we will compare tow numbers using if-else statement and will print the output accordingly.
Example:

 `# Python program to find the` `# maximum of two numbers` `def` `maximum(a, b):` `    ` `    ``if` `a >``=` `b:` `        ``return` `a` `    ``else``:` `        ``return` `b` `    ` `# Driver code` `a ``=` `2` `b ``=` `4` `print``(maximum(a, b))`

Output

```4
```

Method #2: Using max() function
This function is used to find the maximum of the values passed as its arguments.
Example:

 `# Python program to find the` `# maximum of two numbers` `a ``=` `2` `b ``=` `4` `maximum ``=` `max``(a, b)` `print``(maximum)`

Output

```4
```

Method #3: Using Ternary Operator

This operator is also known as conditional expressions are operators that evaluate something based on a condition being true or false. It simply allows testing a condition in a single line

Example:

 `# Python program to find the` `# maximum of two numbers` `    ` `# Driver code` `a ``=` `2` `b ``=` `4` `# Use of ternary operator` `print``(a ``if` `a >``=` `b ``else` `b)` `# This code is contributed by AnkThon`

Output

```4
```

Last Updated on October 26, 2021 by admin

## Is Python call by reference or call by valueIs Python call by reference or call by value

Is Python call by reference or call by value Python utilizes a system, which is known as “Call by Object Reference” or “Call by assignment”. In the event that you pass arguments like whole numbers, strings or tuples to a

## Check if email address valid or not in PythonCheck if email address valid or not in Python

Check if email address valid or not in Python Given a string, write a Python program to check if the string is a valid email address or not. An email is a string (a subset of ASCII characters) separated into

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 ‘+’

## Convert the column type from string to datetime format in Pandas dataframeConvert the column type from string to datetime format in Pandas dataframe

In this tutorial, we will explore how to convert a column of string values to datetime format in a Pandas DataFrame. This is useful when dealing with date or time information stored as strings and needing to perform operations or

## Finding Mean, Median, Mode in Python without librariesFinding Mean, Median, Mode in Python without libraries

Finding Mean, Median, Mode in Python without libraries In this article, we will learn how to calculate Mean, Median, and Mode with Python without using external libraries. Mean : The mean is the average of all numbers and is sometimes called the arithmetic mean.

## Ways to import CSV files in Google ColabWays to import CSV files in Google Colab

Ways to import CSV files in Google Colab Colab (short for Colaboratory) is Google’s free platform which enables users to code in Python. It is a Jupyter Notebook-based cloud service, provided by Google. This platform allows us to train the Machine

## Find length of a string in python (4 ways)Find length of a string in python (4 ways)

Find length of a string in python (4 ways) Strings in Python are immutable sequences of Unicode code points. Given a string, we need to find its length. Examples: Input : 'abc' Output : 3 Input : 'hello world !' Output : 13