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
1
getattr (obj, name,
default)
Ob'ektning atributiga kirish uchun ishlatiladi.
2