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 |
ဆက်စပ်စာမျက်နှာများ
attribute တစ်ခုကို ဖယ်ရှားရန် delattr () လုပ်ဆောင်ချက်
attribute တစ်ခု၏ တန်ဖိုးကိုရယူရန် getattr() လုပ်ဆောင်ချက်
attribute တစ်ခုရှိ၊ မရှိ စစ်ဆေးရန် hasattr() လုပ်ဆောင်ချက်