Answer the question
In order to leave comments, you need to log in
How to compare objects with each other in Python?
It sounds silly, but I need to write a function that takes one argument as input and returns something that is then compared to math and re . Don't ask questions why, just tell me how to do it :) Thank you.
def func(anything):
return something
import math
import re
# оба должны быть True
func(re) <= re
func(re) >= math
TypeError: unorderable types: module() >= module()
Answer the question
In order to leave comments, you need to log in
The returned object must have __ge__ and __le__ methods
class A(object):
def __ge__(self, other):
return True
def __le__(self, other):
return True
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question