第14546题 单选
给定Python的Point、Rect类及实例代码,以下说法正确的是?
class Point:
    def __init__(self,x,y):
        self.x = x
        self.y = y
class Rect:
    def __init__(self,lefttop_point,rightbottom_point):
        self.lefttop = lefttop_point
        self.rightbottom = rightbottom_point
    def __contains__(self,y):
        if self.lefttop.x<=y.x<=self.rightbottom.x and self.lefttop.y<=y.y<=self.rightbottom.y:
            return True
        else:
            return False
rectA = Rect(Point(10,10),Point(20,5))
print(Point(15,18) in rectA)
A

第17行代码执行后将报错,因为Rect类没有定义in运算符

B

第16行代码将Point对象作为参数,将导致错误

C

in是成员运算符,不适用于Rect类

D

由于Rect类定义了contains魔术方法,因此第17行代码能正确执行

提交0次 正确率0.00%
答案解析