• prints the attribute name of the object s print(getattr(s,name)) reset the value of attribute age to 23 setattr(s,"age",23)
  • Jizzax Davlat pedagogika Universiteti




    Download 135,99 Kb.
    Pdf ko'rish
    bet8/15
    Sana20.02.2024
    Hajmi135,99 Kb.
    #159518
    1   ...   4   5   6   7   8   9   10   11   ...   15
    Bog'liq
    M.I Pythonda obyektga yo’naltirilgan dasturlash 6
    Yuza, Bob. Ijtimoiy-iqtisodiy rivojlanishni dasturlash, prognozlashtir, 012, Nukleotidlar ketma-ketliklari boyicha malumotlar bazalari, Kadr ortida matnni o‘qish usullari, Shablon funksiyalarda funksiyalarni qayta yuklash mexanizmi-fayllar.org, 1-mavzu. Falsafaning fan va dunyoqarashga doir mohiyati Reja, Amaliy 5, 8-mavzu6-22, 5-mavzu 6-22 FULL
    setattr (obj, name, 
    value) 
    U ob’ektning o’ziga xos atributiga ma’lum bir 
    qiymatni 
    belgilash uchun ishlatiladi. 

    delattr (obj, name) 
    U ma’lum bir atributni o’chirish uchun ishlatiladi. 



    hasattr (obj, name) 
    Ob’ektda o’ziga xos atribut bo’lsa, u haqiqiy qiymatni 
    qaytaradi. 
    Misol: 
    class Student: 
    def init (self,name,id,age): self.name = name; 
    self.id = id; self.age = age 
    #creates the object of the class Student 
    s = Student("John",101,22) 
    #prints the attribute name of the object s 
    print(getattr(s,'name')) 
    # reset the value of attribute age to 23 
    setattr(s,"age",23) 
    # prints the modified value of age 
    print(getattr(s,'age')) 
    # prints true if the student contains the attribute with name id 
    print(hasattr(s,'id')) 
    # deletes the attribute age 
    delattr(s,'age') 
    # this will give an error since the attribute age has been deleted 
    print(s.age) 
    John 23 
    True 
    AttributeError: 'Student' object has no attribute 'age' 
    O'rnatilgan sinf atributlari
    Boshqa atributlar bilan bir qatorda, python klassida sinf haqida ma'lumot beradigan
    ba'zi bir o'rnatilgan sinf atributlari mavjud. O'rnatilgan sinf atributlari quyidagi
    jadvalda keltirilgan: 

    dict - Bu sinf nomlari maydoni haqidagi ma'lumotlarni o'z ichiga olgan 
    lug'atni taqdim etadi. 

    doc - U sinf hujjatiga ega bo'lgan qatorni o'z ichiga oladi 

    name - U sinf nomiga kirish uchun ishlatiladi. 

    module - Ushbu sinf aniqlangan modulga kirish uchun foydalaniladi. 




    Download 135,99 Kb.
    1   ...   4   5   6   7   8   9   10   11   ...   15




    Download 135,99 Kb.
    Pdf ko'rish