Python setattr() Function

example

تغییر ارزش ویژگی "age" از "person" object:

class Person:
  name = "John"
  age = 36
  country = "Norway"
setattr(Person, 'age', 40)

Run Example

Definition and Usage

setattr() Function specifies the value of the specified attribute of the object.

syntax

setattr(object, attribute, value)

parameter value

parameter description
object مandatory. object.
attribute مandatory. نام ویژگی که می‌خواهید تنظیم کنید.
value مandatory. Required. شما باید ارزش مشخص شده برای ویژگی تعیین شده را اعطاء کنید.

Related Pages

Reference Manual:delattr() Function(حذف ویژگی)

Reference Manual:getattr() Function(دسترسی به ارزش ویژگی)

Reference Manual:hasattr() Function(بررسی وجود ویژگی)