• 函数初认识


    • 函数与面向过程区别

    函数:有返回值

    面向过程:无返回值

    #函数
    def func_1():
        '''说明1'''
        print("func1:")
        return 0
    #面向过程
    def func_2():
        '''说明2'''
        print("func2")
    
    f1 = func_1()
    f2 = func_2()
    print("func_1:",f1)
    print("func_2;",f2)
    
    结果:
    func1:
    func2
    func_1: 0
    func_2; None
    • 具体例子
    import time
    def logger():
        time_format = "%Y-%M-%D- %X"#定义时间显示格式
        time_current = time.strftime(time_format)#根据定义的时间格式显示
        with open("a.txt","a+",encoding="utf-8") as f:
            f.write("%s hello world!
    "%time_current)
    
    def test1():
        print("test1:")
        logger()
    
    def test2():
        print("test2:")
        logger()
    
    def test3():
        print("test3:")
        logger()
    
    test1()
    test2()
    test3()
    • 带参数的函数
    def test(x,y,z):
        '''说明1'''
        print("func1:")
    
    test(1,3,4)
    test(1,3,z=5)
    test(x=1,y=2,z=3)
    test(z=2,x=1,y=6)
  • 相关阅读:
    微信app支付,服务端对接
    git 忽略文件权限
    linux 终端全局代理设置
    centos 谷歌浏览器安装
    putty快速设置本地代理
    centos rpmforge repo
    mysql 同步
    apscheduler 排程
    tornado 排程
    gedit 格式化json
  • 原文地址:https://www.cnblogs.com/cheng662540/p/7994689.html
Copyright © 2020-2023  润新知