Python 函数不';t从列表Pyhton返回多个值 MyHand=[1,2,3] def显示卡(位置): 对于位置中的elm: 如果elm

Python 函数不';t从列表Pyhton返回多个值 MyHand=[1,2,3] def显示卡(位置): 对于位置中的elm: 如果elm,python,list,function,Python,List,Function,尝试以下方法: MyHand =[1,2,3] def DisplayCards(location): for elm in location: if elm <= 4: return(elm) print(DisplayCards(MyHand)) MyHand=[1,2,3] def显示卡(位置): 返回[x为x,如果x如果要返回多个,可以考虑将它们保存到新的列表并返回该列表。 MyHand =[1,2,3] def DisplayCards(locat

尝试以下方法:

MyHand =[1,2,3]

def DisplayCards(location):
  for elm in location:
    if elm <= 4:
      return(elm)

print(DisplayCards(MyHand))
MyHand=[1,2,3]
def显示卡(位置):
返回[x为x,如果x<4,则位置为x]
打印(显示卡(MyHand))

< /代码>如果要返回多个,可以考虑将它们保存到新的列表并返回该列表。
MyHand =[1,2,3]

def DisplayCards(location):
   return [x for x in location if x < 4] 


print(DisplayCards(MyHand))