首页 > 编程语言 >Python中,函数的返回值

Python中,函数的返回值

时间:2022-08-19 15:13:11浏览次数:66  
标签:return 函数 Python print 返回值 odd def

def fun(num):
    odd=[]#存奇数
    even=[]#存偶数
    for i in num:
        if i%2:
            odd.append(i)
        else:
            even.append(i)
    return odd,even

#函数的调用
lst=[10,29,33,45,49,94]
print(fun(lst))
'''
函数的返回值:
          (1)如果函数没有返回值[函数执行完毕之后,不需要给调用处提供数据]return可以省略不写
          (2)函数的返回值,如果是1个,直接返回类型
          (3)函数的返回值,如果是多个,返回的结果为元组
'''
def fun1():
    print('hello')
fun1()

def fun2():
    return 'hello'
result=fun2()
print(result)

def fun3():
    return 'hello','world'
res=fun3()
print(res)

 

标签:return,函数,Python,print,返回值,odd,def
From: https://www.cnblogs.com/yin-qiu-moon/p/16602043.html

相关文章

  • python激活
    Pycharm又过期了怎么办? 方法一:(亲测可用)1、打开网址: lookdiv.com 2、在输入框输入钥匙:lookdiv.com3、点击“获取激活码”按钮,获取激活码 4.激活后可以使用几......
  • python-zip()函数-zip*函数-压缩-解压缩
    python-zip()函数-压缩-解压缩zip()函数:将多个序列(列表、元组、字典、集合、字符串以及range()构成的列表)按一定规则重新组成一组元组。常与list()函数搭配使用,list......
  • python中的@的使用
    在python中,@是一个装饰器,针对某个函数,起调用传参的作用。具体怎么用的可以参考如下代码:defA(fn):print("a")fn()defB():print("b")@AdefC():......
  • python数据类型---字典dict
    python数据类型---字典dict1.基本认识字典是Python里一种常用的数据类型,键值对,keyvalue对,它用于存放具有映射关系的数据。字典中的数据是无顺序的。。。。。。d={key......
  • python菜鸟学习: 10. 函数的基本用法
    #-*-coding:utf-8-*-#回参函数deftest01():return0#以元组返回参数deftest02():return1,[1,2,3,4,5],{"name":"liyuzhoupan"}#有参函数deftest......
  • 【Python】使用requests_html解析HTML页面
    1、官网https://pypi.org/project/requests-html/ 2、githubhttps://github.com/kennethreitz/requests-html 3、安装pipinstallrequests-html  4、使用......
  • Python数据类型
    在Python3中,有6种标准的数据类型:Number(数字)、String(字符串)、List(列表)、Tuple(元组)、Set(集合)、Dictionary(字典),见表2-2。  Python3中支持3种不同的数值类型,包括int(整型......
  • 面试 写函数 有什么好的习惯
    1·以JSDoc的形式,去写函数注释2· 写代码 一直遵循DRY  原则 ( DRY  ——>  Don't RepectYouself)但凡我写的代码,重......
  • 渲染头像和名字的函数(jQuery)
    functionrenderAvatar(user){varname=user.nickname||user.username;//利用或以及字符串的先后顺序当nickname为空时则选择username,当他不为空......
  • Pybinder-python与c++的调用
    目录Areallygoodproject.ExportCpptopythonunerLinuxplatformAreallygoodproject.https://github.com/pybind/pybind11https://github.com/pybind/pyb......