ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
## 1. bool bool() 函数用于将给定参数转换为布尔类型,如果没有参数,返回 False。 ~~~ >>>bool() False >>> bool(0) False >>> bool(1) True >>> bool(2) True >>> issubclass(bool, int) # bool 是 int 子类 True ~~~ ## 2. vars vars() 函数返回对象object的属性和属性值的字典对象,如果没有参数,就打印当前调用位置的属性和属性值 类似 locals()。 ### 2.1 返回对象的属性值 ~~~ class People(object): def __init__(self,name,age): self.name = name self.age = age def introdution(self): print("我是{0},今年{1}岁".format(self.name,self.age)) if __name__ == '__main__': value = vars(People("代林",28)) print(type(value)) print(value) print(value.values()) ~~~ ~~~ <class 'dict'> {'name': '代林', 'age': 28} dict_values(['代林', 28]) ~~~