Which of the following Python code will print True?
a = foo(2)
b = foo(3)
print(a < b)
a = foo(2)
b = foo(3)
print(a < b)A.
class foo:
def __init__(self, x):
self.x = x
def __lt__(self, other):
if self.x < other.x:
return False
else:
return TrueB.
class foo:
def __init__(self, x):
self.x = x
def __less__(self, other):
if self.x > other.x:
return False
else:
return TrueC.
class foo:
def __init__(self, x):
self.x = x
def __lt__(self, other):
if self.x < other.x:
return True
else:
return FalseD.
class foo:
def __init__(self, x):
self.x = x
def __less__(self, other):
if self.x < other.x:
return False
else:
return TrueAnswer: Option C
Related Questions on Classes and Objects in Python
A. A blueprint for creating objects
B. A built-in function
C. A specific data type
D. A variable in Python
How do you define a class in Python?
A. Using the class keyword
B. Using the define keyword
C. Using the classdef keyword
D. Using the class method
A. Instances of a class
B. Built-in functions
C. Special data types
D. Global variables
How do you create an object of a class in Python?
A. Using the class name and parentheses
B. Using the create() method
C. Using the new keyword
D. Using the object() method

Join The Discussion