Discuss / Python / 交作业

交作业

Topic source

   if L==[]:

      return (None,None)

   min=L[0]

   max=L[0]   

   for x in L:

      if x<min:

         min=x

      if x>max:

         max=x

   return (min,max)

你好可以解释一下这个代码吗?

1.为什么return后面不用加else了?

2.为什么要把L[0]赋值给max和min

活力老汤

#3 Created at ... [Delete] [Delete and Lock User]

1,是if后面没有else吧?可以不用elif,因为比较过后不执行

2,赋值是初始化max和min


  • 1

Reply