函数
函数参数中的*和**参数含义
Python函数参数包括位置参数、关键字参数
*
和**
参数都用来接收未知数量的参数,*
参数将接收的参数作为元组传入,**
将关键字参数作为字典传入;
def func(**kargs):
print(type(kargs))
a = kargs["abc"]
print(a)
print(kargs["name"])
def func1(name, abc):
print(abc)
print(name)
def func2(*args):
print(type(args))
print(args)
dict = {"abc":10, "name":"zhanghaiming"}
func(**dict)
func1(**dict)
func2(1,2)
输出:
<class 'dict'>
10
zhanghaiming
10
zhanghaiming
<class 'tuple'>
(1, 2)
【参考】
1、https://www.cnblogs.com/arkenstone/p/5695161.html
内置函数
其他
property属性使用:
https://www.liaoxuefeng.com/wiki/897692888725344/923030547069856
https://blog.csdn.net/AlanGuoo/article/details/78855750
作为装饰器,将类的成员函数变成属性的直接调用,可以实现对成员函数的取值检测等运算操作;
staticmethod用法:
raise用法:
相当于直接中断程序执行
raise NotImplementedError
raise FileNotFoundError
Python忽略警告信息
Python的警告信息有时候很烦人,特别是因为软件版本引起的警告,下面的代码可以去掉python输出的警告:
import warnings
warnings.filterwarnings("ignore")