Comparing the modules in Python. OK, but why?
I was going through a question in Checkio. And then i came across this.
import re,math
re > math # returns True
math > re # returns False
Can someone explain how Python compares between ANY two THINGS.
Does python does this thing by providing a hierarchy for modules. Furthermore,
re > 1 # return True # Ok, But Why?
I would really appreciate some deep explanations on these things!
Everthing is an object. And modules are no exception. Therefore:
import re, math
print(id(re), id(math))
print(re > math)
print(id(re) > id(math))
print(re < math)
print(id(re) < id(math))
print(id(re), id(math))
In my case:
39785048 40578360
False
False
True
True
39785048 40578360
Your mileage may vary, because your ids will not be mine and therefore the comparison may be reversed in your case.
链接地址: http://www.djcxy.com/p/89686.html