Python对象的属性可以通过obj.__dict__获得,向其中添加删除元素就可以实现python对象属性的动态添加删除的效果,不过我们应该使用更加正规的getattr和setattr来进行这类操作 getattr(object, name[, default]) Return the value of the named attribute of object. name must be a string. If the string is the name of one of the ob
在C#里面,属性的get 与 set 非常简单方便. public class bird { public int age { get;set; } public bool isadult { get { return this.age >= 1 ? true:false; } } } 而在Python里面,属性可以直接获取或赋值.但是如果在获取或赋值时加一些逻辑判断,就稍微有点不一样. class bird(object): def getAge(self): if age < 1 :ret