Code:
class Fraction(object):
def __init__(self, num, denom):
self.numerator = num
self.denominator = denom
def main():
f = Fraction(1, 3)
print type(f)
if __name__ == "__main__":
main()
Output:
<class '__main__.Fraction'>
Question:
- Why is the type
__main__.Fraction
instead of just Fraction
?
Why is there "." between __main__
and Fraction
? "." implies that Fraction
is a sub-class of __main__
. But why? Even if I remove If __name__ == "__main__"
from the code, I still get the same output:
class Fraction(object):
def __init__(self, num, denom):
self.numerator = num
self.denominator = denom
f = Fraction(1,3)
print type(f)
output: <class '__main__.Fraction'>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…