Example:  class Employee




Download 135,99 Kb.
Pdf ko'rish
bet7/15
Sana20.02.2024
Hajmi135,99 Kb.
#159518
1   2   3   4   5   6   7   8   9   10   ...   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
Example: 
class Employee: 
def init (self,name,id): 
self.id = id; self.name = name; 
def display (self): 
print("ID: %d \nName: %s"%(self.id,self.name)) 
emp1 = Employee("John",101) emp2 = Employee("David",102) 
#accessing display() method to print employee 1 information 
emp1.display(); 
#accessing display() method to print employee 2 information 
emp2.display(); 
ID: 101 
Name: John ID: 102 
Name: David 
Misol: Sinf ob'ektlari sonini hisoblash 


class Student: count = 0 
def init (self): 
Student.count = Student.count + 1 
s1=Student() s2=Student() s3=Student() 
print("The number of students:",Student.count) 
The number of students: 3 
Pythonning parametrlanmagan konstruktorga misoli
class Student: 
# Constructor - parametrlanmagan 
def init (self): 
print("This is non parametrized constructor") 
def show(self,name): print("Salom",name) 
student = Student() student.show("hghyg") 
Pythonning parametrlangan konstruktorga misol
class Student: 
# Constructor - parameterized 
def init (self, name): 
print("This is parametrized constructor") self.name = name 
def show(self): print("Hello",self.name) 
student = Student("John") student.show() 
Hello John 
Python ichki sinf vazifalari
Sinfda aniqlangan ichki funktsiyalar quyidagi jadvalda tavsiflangan. 
SN Funksiya 
Vazifasi 

getattr (obj, name, 
default) 
Ob'ektning atributiga kirish uchun ishlatiladi. 


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




Download 135,99 Kb.
Pdf ko'rish