I have a code in Python:
class House:
def __init__(self, Address, Bedrooms, Bathrooms, Garage, Price):
self.Address= Address
self.Price = Price
self.Bathrooms= Bathrooms
self.Garage= Garage
if Garage == 1:
x="Attached garage"
else:
x="No Garage"
def getPrice(self):
return self.price
h1 = House("1313 Mockingbird Lane", 3, 2.5, True, 300000)
h2 = House("0001 Cemetery Lane", 4, 1.75, False, 400000)
now if I type print(h1) I want all the object to be shown as a multi-lined string. For Example:
print(h1) gives
1313 Mockingbird Lane
Bedrooms: 3 Bathrooms: 2.5
Attached garage
Price: 300000
__str__(self)method in your class returning a multi-line string.