zoukankan      html  css  js  c++  java
  • 函数的定义

    '''
    python中函数定义:函数是逻辑结构化和过程化的一种编程方法
    
    python中函数定义方法:
    
    def test(x):
       "The function definitions"
       x += 1
       return x
    
    def:定义函数的关键字
    test:函数名
    ():内可定义形参
    "":文档描述(非必要,但是强烈建议为你的函数添加描述)
    x+=1:泛指代码块或程序处理逻辑
    return:定义返回值
    调用运行:可以带参数也可以不带
    函数名()
    '''
    
    def test(x):
       "计算一个数学函数"
       y = 2*x + 1
       return y
    
    z = test(1)
    print(z)
    
    
    '''函数返回值'''
    
    #过程:就是没有返回值的函数
    def test01():
       "这是函数描述"
       msg = 'hello The little green frog'
       print(msg)
    
    def test02():
       "这是函数描述"
       msg = 'hello WuDaLang'
       print(msg)
       return msg
    
    def test03():
       "这是函数描述"
       msg = 'test03'
       print(msg)
       return 1, '2', ['3', 4], (5, '6'), {'7':'8'}
    
    t1 = test01()
    t2 = test02()
    t3 = test03()
    
    print('from test01 return is %s' % t1)
    print('from test02 return is %s' % t2)
    print('from test03 return is {}, {}, {}, {}, {}'.format(*t3))
    
    #总结:返回值=0,返回None;返回值=1,返回object;返回值>1,返回tuple;
    while True: print('studying...')
  • 相关阅读:
    Android和C#实时视频传输Demo
    cocos2d-x3.0 windows 环境配置
    WPF六个控制概述
    高度并行的指令级的超级处理器
    Oracle存储过程的简单示例
    SharePoint Search之(两)持续抓取Continues crawl
    第28周三
    第28周二
    第28周一
    第27周日
  • 原文地址:https://www.cnblogs.com/xuewei95/p/14410284.html
Copyright © 2011-2022 走看看