函数

一、定义一个函数

def hello(name):
    print('hello ' + name)
    
name = input('请输入您的用户名: ')
hello(name)

二、多参数

def hello(name1,name2):
    print('hello ' + name1 + ' ' +name2)
    
name1 = input('name1: ')
name2 = input('name2: ')
hello(name1,name2)

三、不定数目参数

def hello(*args):
    print(type(args))      //类型是元组
    for i in args:
        print(i)
    

hello(1,2,3)

def hello(**kwargs):
    print(type(kwargs))      //类型是字典
    for item in kwargs.items():
        print(item[0] , end=' ')      //结尾不是\n换行,而是空格
        print(item[1])
    

hello(a=1,b=2,c=3)

四、返回值

def test(a,b,c):
    return a+b , a-b , a+c , b+c
    
a,b,c,d = test(1,2,3)
print(a)
print(b)
print(c)
print(d)

posted @ 2020-12-02 15:10  lnterpreter  阅读(64)  评论(0编辑  收藏  举报