Answer the question
In order to leave comments, you need to log in
How to correctly compose a class with a self argument?
What am I doing wrong?
class Person:
name = "Кристи"
age = 10
def set(self, name, age):
self.name = name
self.age = age
lena = Person()
lena.set = ("Лена", 25)
print(lena.name + " " + str(lena.age))
ivan = Person()
ivan.set = ("Иван", 33)
print(ivan.name + " " + str(ivan.age))
Кристи 10
Кристи 10
Answer the question
In order to leave comments, you need to log in
Your set is a function. Accordingly
, arguments can also be passed directly when creating an instance of the class
ivan.set("Иван", 33)
class Person:
name = "Кристи"
age = 10
def __init__(self, name, age):
self.name = name
self.age = age
def set(self, name, age):
self.name = name
self.age = age
ivan = Person('Иван', 33)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question