给定两个数字, 编写Python代码以查找这两个数字的最大值。
例子:
Input: a = 2, b = 4
Output: 4
Input: a = -1, b = -4
Output: -1
方法1:这是幼稚的方法, 我们将使用如果别的语句, 并将相应地输出输出。
例子:
# 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))
输出如下:
4
方法2:使用max()函数
此函数用于查找作为参数传递的最大值。
例子:
# Python program to find the
# maximum of two numbers
a = 2
b = 4
maximum = max (a, b)
print (maximum)
输出如下:
4
首先, 你的面试准备可通过以下方式增强你的数据结构概念:Python DS课程。

![从字法上最小长度N的排列,使得对于正好为K个索引,a[i] a[i]+1](https://www.lsbin.com/wp-content/themes/begin%20lts/img/loading.png)