Answer the question
In order to leave comments, you need to log in
OOP. Why is none displayed?
class Human:
def __init__(self, head, body, legs):
self.head = head
self.body = body
self.legs = legs
def ChangePartHead(self, head, scrap):
scrap.head = head
class Robot:
head = "MetalHead"
body = "MetalBody"
legs = "MetalLegs"
def ChangePartLegs(self, legs, meat):
meat.legs = legs
obj1 = Human('FleshHead', 'FleshBody', 'FleshLegs')
obj = Robot()
print(obj1.ChangePartHead(obj1.head, obj))
print(obj.ChangePartLegs(obj.legs, obj1))
Answer the question
In order to leave comments, you need to log in
print(obj1.ChangePartHead(obj1.head, obj))
Prints what is returned by the ChangePartHead method of the obj1 object. The specified method does not return anything, which is why None is output.
To correctly print, use the magic methods __repr__ and __str__, also read this article: habrahabr.ru/sandbox/82471
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question