0

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.

fsociety
  • 977
  • 3
  • 12
  • 23
  • 2
    Q1. str is a type object... subtle difference... Q2. main is the namespace... Q3. they are different variables ... Q4 yes True, however im not sure what you mean by id(function object) – Joran Beasley Jan 30 '17 at 17:20
  • 1
    `id(function object)` means that you have to execute `id(TestFun)` – furas Jan 30 '17 at 17:21

0 Answers0