随笔分类 - python进阶知识点
摘要:问题:通过装饰器想对函数参数进行强制类型检查,并且指定所有参数类型,也可以指定部分参数类型 未装饰的函数: def spam(x, y, z=42): print(x,y,z) spam('hello',1) #hello 1 42 写装饰器前,运用到了inspect中的signature签名函数,
阅读全文
摘要:一、*args的使用方法 *args 用来将参数打包成tuple给函数体调用 例子一: def function(*args): print(args, type(args)) function(1) #(1,) <class 'tuple'> 例子二: def function(x, y, *ar
阅读全文
摘要:考察 Student 类: class Student(object): def __init__(self, name, score): self.name = name self.score = score 当我们想要修改一个 Student 的 scroe 属性时,可以这么写: s = Stu
阅读全文

浙公网安备 33010602011771号