pu369com

python 函数返回值(总结)

没有返回值的叫过程

 

def test1():
msg="我是一个过程"
print(msg)

 

 

有return的叫函数

def test02():
msg="我是函数,有返回值"
print(msg)
return msg
关于返回的值: 定义的函数可以返回多个值,组合成元组
def test03():
  msg='我要返回多个值'
  print(msg)
  return msg,"hello xiaozhu",[1,2,3,4,5],{'name':'zhou','age':18}

t3=test03()
print('test03的结果:'+'\n'+'\t'+str(t3))

 

test01的结果:
 None
test02的结果:
 我是函数,有返回值
test03的结果:
 ('我要返回多个值', 'hello xiaozhu', [1, 2, 3, 4, 5], {'name': 'zhou', 'age': 18})

 

参考:https://www.cnblogs.com/Hanro-Z/p/9249860.html

posted on 2020-03-30 15:16  pu369com  阅读(315)  评论(0编辑  收藏  举报

导航