Python data analysis script necessary knowledge (5)
1. Four parameter types of parameter passing in Python
"""
函数的参数
1.位置参数 def test1(x,y): x,y就是位置参数
2.默认参数 def test2(x,y=1) y就是默认参数
3.可变参数 def test3(*args) 函数内部参数可变,收到的是tuple
4.关键字参数 def test4(**Kwargs) 允许不定长的键值对,自动组装为一个dict
"""
# 可变参数
def func1(f,*args):
print(f,type(f))
print(args,type(args))
nums = [4,5,6]
func1(1,2,*nums)
li = '测试'
func1(2,*li)
# 4.关键字参数
def func2(name,age,**kwargs):
print('name:',name,'age:',age,'other:',kwargs,type(kwargs))
func2('jack',30,city='shanghai')
2. Actual usage scenarios of decorators
1. Basic decorator (decorate a function without parameters)
"""
Python装饰器高级版————Python类内定义装饰器并传递self参数
本测试重点:解决类里面定义的装饰器,在同一个类里面使用的问题, 并实现了装饰器的类熟悉参数传递
"""
# 基本装饰器 (装饰不带参数的函数)
def clothes(func):
def wear():
pr