正在加载图片...
Accessing Attributes There are built-in functions that can help us access attributes. Using getattr,we can look up an attribute using a string instead. getattr(<expression>,<attribute_name (string)>) getattr(a,'balance)is the same as a.balance getattr(Account,'balance)is the same as Account.balance Using hasattr,we can check if an attribute exists. hasattr(<expression>,<attribute_name (string)>) hasattr(a,'balance)returns True hasattr(Account,'balance)returns FalseAccessing Attributes There are built-in functions that can help us access attributes. Using getattr, we can look up an attribute using a string instead. - getattr(<expression>, <attribute_name (string)>) - getattr(a, 'balance') is the same as a.balance - getattr(Account, 'balance') is the same as Account.balance Using hasattr, we can check if an attribute exists. - hasattr(<expression>, <attribute_name (string)>) - hasattr(a, 'balance') returns True - hasattr(Account, 'balance') returns False
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有