函数返回值return,列表字典的拆包

def test1():
  print('hello')       #函数无返回值

def test2():
  print('world')
  return 1         #函数有返回值, 可以定义一个变量var = return 1

def test3():
  print('suqin')                           #函数的返回值是元组
  return 1, 'lvhonglei', [2, 3], {'name': 'suqin','age':'18'}
  #return x+y
  #return test2          可以返回表达式,函数
test1()
test2()
test3()
print('----------------------------------------------------')
x = test1()
y = test2()
z = test3()
print(x)      # 返回的是整个函数体的结果,test1无返回值,那么打印none
print(y)
print(z)

执行结果

hello
world
suqin
----------------------------------------------------
hello
world
suqin
None
1
(1, 'lvhonglei', [2, 3], {'name': 'suqin', 'age': '18'})


 

a,b = (1,2)

a,b = [1,2]

 

a,b = {"name":"suqin","age":18}

a = name

b = age

 

a,b = {"name":"suqin","age":18}.items()

a = ("name","suqin")

b =  ("age",18)

 

posted @ 2017-07-18 15:07  西湖歌舞几时休  阅读(300)  评论(0编辑  收藏  举报