Python-函数的返回值

函数返回多个值时,结果为元组。

 1 def fun(num):
 2     odd = [] # 存奇数
 3     even = [] # 存偶数
 4     for i in num:
 5         if i%2:
 6             odd.append(i)
 7         else:
 8             even.append(i)
 9     return odd, even
10 #函数的调用
11 lst = [10, 29, 34, 23, 44, 53, 55]
12 print(fun(lst))
13 
14 def fun1():
15     print('hello')
16     #return
17 fun1()
18 
19 def fun2():
20     return 'hello'
21 res = fun2()
22 print(res)
23 
24 def fun3():
25     return 'hello', 'world'
26 print(fun3())

 

posted @ 2022-02-26 14:10  Xxiaoyu  阅读(76)  评论(0编辑  收藏  举报