互联网技术 / 互联网资讯 · 2024年3月12日

Python内置函数-setattr()函数详解及云计算开发

setattR() 函数对应函数 getattR(),用于设置属性值,该属性不一定是存在的。

以下是 setattR() 方法的语法:

setattR(object, naMe, value)

object — 对象。

naMe — 字符串,对象属性。

value — 属性值。

以下实例展示了 setattR() 函数的使用方法:

对已存在的属性进行赋值:
云计算开发:Python内置函数-setattr()函数详解

如果属性不存在会创建一个新的对象属性,并对属性赋值:
云计算开发:Python内置函数-setattr()函数详解

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.

登录免费注册