zoukankan      html  css  js  c++  java
  • 函数返回值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)

    life is short,i need python
  • 相关阅读:
    flask多线程多协程操作
    flask介绍
    centos django+Nginx+uwsgi部署
    centos下运行python3.6+Django+mysql项目
    centos虚拟机下安装nginx
    redis安装
    路飞学城课程_课程详细_作业点评
    redis使用方式
    git命令学习
    组合&多态&封装
  • 原文地址:https://www.cnblogs.com/lvhonglei-python/p/7200571.html
Copyright © 2011-2022 走看看