提示信息

Python setattr、getattr、hasattr

云和山的彼端 已关注

setattr(obj, attr, value) is a built-in Python function that sets the value of a given attribute (attr) of an object (obj) to the specified value.

getattr(obj, attr, default) is a built-in Python function that returns the value of a given attribute (attr) of an object (obj). If the attribute doesn't exist, it returns the default value specified. If the default value is not specified and the attribute doesn't exist, it raises an AttributeError.

hasattr(obj, attr) is a built-in Python function that checks if an object (obj) has a given attribute (attr). It returns True if the attribute exists, and False otherwise.

    遇到难题? "AI大模型GPT4.0、GPT" 是你的私人解答专家! 点击按钮去提问......
云和山的彼端 关注 已关注

最近一次登录:2023-10-09 16:05:31   

暂时还没有签名,请关注我或评论我的文章
×
免费图表工具,画流程图、架构图