Ota sinf yaratish


Ota sinf yaratish

Har qanday sinf ota sinf bo‘lishi mumkin, shuning uchun sintaksis boshqa har qanday sinfni yaratish bilan bir xil:

Misol

firstname va lastname xususiyatlari hamda printname metodiga ega Person nomli sinf yarating:

class Person:   def __init__(self, fname, lname):     self.firstname = fname     self.lastname = lname   def printname(self):     print(self.firstname, self.lastname) #Use the Person class to create an object, and then execute the printname method: x = Person("John", "Doe") x.printname()
O‘zingiz sinab ko‘ring »



W3Schools Pathfinder

Yutuqlaringizni kuzating – bu bepul!