Python Üst Sınıf (Parent Class) Oluşturma

C

CapsLock

Enough
Thread Starter
Ultra Member
Joined
Nov 5, 2019
Messages
959
Reaction score
718
Location
Peak
Herhangi bir sınıf bir üst sınıf olabilir, bu nedenle sözdizimi, başka bir sınıf oluşturmakla aynıdır.

Örnek:

firstname
ve lastname özellikleri ve bir printname metodu ile ile Person adında bir sınıf oluşturalım.

Python:
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()
 
SPAM IS FORBIDDEN!
  • SPAMMERS ARE BANNED FROM THE FORUM AND CANNOT USE ANY OF THE CHEATS
  • For example: thanks, thx, very good, asdqwe, working, ty and so on!
  • For example: Writing the same message over and over. thanks, thx and so on!
  • Copying and copying someone else's message is prohibited.
  • It is forbidden to send messages to increase the number of comments on threads that you have no knowledge of.
  • Write your own opinion when commenting!
  • If you see spam message, please let us know with the REPORT button!

Theme editor

Top Bottom