zoukankan      html  css  js  c++  java
  • 人生苦短_我用Python_def(函数)_004

    # coding=utf-8
    
    # function函数:内置函数
    # 例如: len int extent list range str
    # print insert append pop reverse sort
    # upper strip  split lower
    
    # 特点、作用:
    # 1、可以直接调用
    # 2、可以重复调用
    # def ----->> definition function
    # 函数  def  关键字  函数名/方法名 ->>有class、def就是方法;无class就是函数
    
    # 定义函数
    
    '''
    def print_list():
        list_ = [1, 2, 3, 4, 5]
        print(list_)
    
    
    # 调用函数  函数名()
    print_list()
    '''
    
    '''
    def demo_(list_):
        for items in list_:
            print('language very good: %s' % items)
    
    
    list_ = ['python', 'demo', 'function', 'css', 'javascript']
    demo_(list_)
    '''
    
    '''
    def demo__(age, name):
        print(age + '的岁数', name + '是名字')
    
    
    demo__('11', 'demo')
    
    # 函数可以有多个参数,但是函数体里面,但不一定要全部都用
    # 函数定义的时候,需要几个位置参数,那么调用函数的时候,也要传递几个参数
    # 完成任意连续整数序列的累加计算
    def dem_test(a, b):
        sum_ = 0
        for items in range(a, b):
            sum_ += items
        print(sum_)
    
    
    dem_test(22, 99)
    '''
    
    # name为位置参数、age为默认参数
    # 默认参数一定是在位置参数后面,不然会报错->age:默认值为十八,同类型字符用"+"号拼接,不同类型用","号拼接
    # 也可以全部传默认参数
    def str_demo(name, age='十八'):
        print(name+'', age, '最棒的......')
    
    
    str_demo('demo')  # demo 18 最棒的......
    
    '''
    def 函数名(位置参数,默认参数):
        # 函数名  见名知意 按照规范去做
        # 位置参数  一定是默认参数之前
        # 可以有多个位置参数,也可以有多个默认参数
        # 函数调用:  函数名(位置参数,*****)
    '''
  • 相关阅读:
    第一章—v-text和v-html
    第一章—v-for
    第一章—v-show
    react_9
    【软件工程】
    【软件工程】网页设计基础 第一章
    【软件工程】psp四则运算
    【python】网络爬虫与信息提取
    【python】数据库学习笔记,设计自己的大学排名
    【python】用python玩微信跳一跳小游戏
  • 原文地址:https://www.cnblogs.com/mrchenyushen/p/9094683.html
Copyright © 2011-2022 走看看