zoukankan      html  css  js  c++  java
  • python

    # -*- coding:utf-8 -*-

    '''
    @project: jiaxy
    @author: Jimmy
    @file: study_函数.py
    @ide: PyCharm Community Edition
    @time: 2018-11-08 09:08
    @blog: https://www.cnblogs.com/gotesting/

    '''


    # 函数
    # append pop insert len range print input int str list replace strip find split

    s = '1234567890ABCDEFGHIJKLMN'
    print(len(s))

    '''
    def 函数名(参数):
    代码块
    return 变量的个数
    '''
    def sums(a,b):
    sums = 0
    for i in range(a,b):
    sums += i
    return sums
    count = sums(1,100)
    print(count)


    # 参数可以有0个,也可以有多个
    # 参数分为位置参数(形参)、动态参数、默认参数、关键字参数
    # 默认值必须放在 位置参数后面

    # 参数,按顺序赋值
    # 指定关键字,关键字跟参数名保持一致
    # return表示当前函数已终止

    def hello(name='Jimmy',content='Hello'):
    print('{},{}!'.format(name,content))
    return name

    hello()
    hello('Tom')
    hello('Jack','Hi')
    hello(content='Marry',name='Good')

    t = hello('abcd','defg')
    print(t)


    # 动态参数===不定常参数===不定个数===想输入几个就输入几个
    # 动态参数 *变量名 args=arguments

    def coding(*args):

    # print(args) #不定长参数变成了元组
    return args

    c = coding('python','java','c','ruby','go')
    print(c)



    # 关键字参数 **kwargs --- key word agruments

    def student_info(**kwargs):
    print(kwargs) #变成了字典

    student_info(name='Jimmy',age=18,lover='study')



    # 各类型参数可以混合使用,但要注意顺序
    # 位置,动态,默认,关键字
    def print_msg(a,*args,b=10,**kwargs):
    print('a',a)
    print('b',b)
    print('args',args)
    print('kwargs',kwargs)

    print_msg(1,2,3,4,5,6)

    
    
  • 相关阅读:
    PAT A1094 The Largest Generation (25 分)——树的bfs遍历
    PAT A1055 The World's Richest (25 分)——排序
    PAT A1052 Linked List Sorting (25 分)——链表,排序
    PAT A1076 Forwards on Weibo (30 分)——图的bfs
    辅导员
    辅导员面试
    C程序设计
    Excel VBA 基本概念
    Excel函数
    导入excel表的数据到数据库ssh
  • 原文地址:https://www.cnblogs.com/gotesting/p/9929628.html
Copyright © 2011-2022 走看看