Please consider the below code:
>>> a='hello'
>>> a.__class__
<type 'str'>
>>>
>>> class Test(object):
... def __init__(self):
... print 'I am in init'
...
>>>
>>> o1=Test()
I am in init
>>> o1.__class__
<class '__main__.Test'>
>>>
I have the below basic questions:
Q1:From the above code, is it right to say that a
is an object of class str
?
Is str
a class? How can we confirm?
Q2:I understand o1
is an object of class Test.What does __main__
denote in <class '__main__.Test'>
?
Q3:Why is there a difference in output of a.__class__
and o1.__class
?
Q4:I also read that even functions in Python are considered objects.So, when i do, def TestFun():
, i read that TestFun
is a variable that points to function object. So, id(TestFun)
should be equal to id(function object)
.Please suggest how can i retrieve both the id to confirm my understanding.