第26937题
有关给定Python代码的说法正确的是?
class Point:
    def __init__(self,X,Y):
        self.x = X
        self.y = Y

class Rect:
    def __init__(self,lefttop_Point,rightbottom_Point):
        self.left_top = lefttop_Point
        self.right_bottom = rightbottom_Point
    def __contains__(self,xy):
        if self.left_top.x <= xy.x <= self.right_bottom.x \
                and self.right_bottom.y <= xy.y <= self.left_top.y:
            return True
        return False

rectA = Rect(Point(10,10),Point(20,5))
print(Point(15,8) in rectA)
A

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

B

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

C

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

D

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

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