وظيفة Python setattr ()
مثال
غيّر قيمة خاصية "العمر" لكائن "الشخص":
class Person:
name = "John"
age = 36
country = "Norway"
setattr(Person, 'age', 40)
التعريف والاستخدام
تحدد الوظيفة setattr()
قيمة السمة المحددة للكائن المحدد.
بناء الجملة
setattr(object, attribute, value)
قيمه المعامل
Parameter | Description |
---|---|
object | Required. An object. |
attribute | Required. The name of the attribute you want to set |
value | Required. The value you want to give the specified attribute |
الصفحات ذات الصلة
الدالة delattr () لإزالة سمة
دالة getattr () للحصول على قيمة السمة
دالة hasattr () للتحقق من وجود سمة