面试题答案
一键面试class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
def is_square(self):
return self.width == self.height
if __name__ == "__main__":
rect1 = Rectangle(5, 5)
rect2 = Rectangle(4, 6)
if rect1.is_square():
print("rect1是正方形")
else:
print("rect1不是正方形")
if rect2.is_square():
print("rect2是正方形")
else:
print("rect2不是正方形")