|
class Employee: def __init__(self,name,id)
|
səhifə | 76/81 | tarix | 13.12.2023 | ölçüsü | 1,14 Mb. | | #176038 |
| k100001
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
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
class Student:
# Constructor - parametrlanmagan def __init__(self): print("This is non parametrized constructor")
def show(self,name): print("Salom",name)
student = Student() student.show("Abbosbek")
|
Salom Abbosbek
class Student:
# Constructor - parameterized def __init__(self, name): print("This is parametrized constructor") self.name = name
def show(self): print("Hello",self.name)
|
Dostları ilə paylaş: |
|
|