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 justFraction
? Why is there "." between
__main__
andFraction
? "." implies thatFraction
is a sub-class of__main__
. But why? Even if I removeIf __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'>