Python常用总结——捋一捋Python中经常遇到的知识点

函数

函数参数中的*和**参数含义

https://www.cnblogs.com/arkenstone/p/5695161.html

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)

内置函数

其他

property属性使用:

https://www.liaoxuefeng.com/wiki/897692888725344/923030547069856

https://blog.csdn.net/AlanGuoo/article/details/78855750

作为装饰器,将类的成员函数变成属性的直接调用,可以实现对成员函数的取值检测等运算操作;

staticmethod用法:

raise用法:

相当于直接中断程序执行

raise NotImplementedError
raise FileNotFoundError

你可能感兴趣的:(Python)