Some questions regarding terminology and meanings


I am not stuck at any particular exercise, but I do have some conceptual questions which I wish to find out more about. I dug around in the forum archives but the other questions were mostly about how to debug a particular code/how to pass the exercise :frowning:

Here are my questions:

  1. Are objects and instances the same thing? I get the feeling that object is a broader term, but I am not really sure...In fact, one of the exercises mentioned something along the lines of "the first argument that __init__() gets is used to refer to the instance object...."

  2. Are functions under classes known as methods as well?

  3. When do you have to store an attribute under the parameter/argument(?) ?

In an earlier exercise (, there was such an example code:

class Square(object):
  def __init__(self):
    self.sides = 4

my_shape = Square()
print my_shape.sides

but all subsequent exercises follow this format instead:

class Animal(object):
    def __init__(self, name): = name

zebra = Animal("Jeffrey")

So why does the second example need 2 arguments in order to have an attribute, while the first only require one to have an attribute?

4.Oh and also, what is the point of creating a class since they work in a way that is very similar to functions? Why not just create a function and then call the function with different arguments instead?

Thank you very much! :slight_smile:




Hey, great questions, @umopapsidn and great links, @leonhard.wettengmx.n :slight_smile:

Yeah, anything that has a type is an object. It is an instance of its type.

Try out this code to check out some types; see the comments ...

# Check the types of four objects
print type(42)
print type(3.14159265)
print type([1, 2, 3, 4, 5])
print type({"one": 1, "two": 2, "three": 3})

# Create a new type named Cat
class Cat(object):
    def __init__(self, name): = name

# Create an instance of Cat        
jas = Cat("Jasper")
# Check the type of our instance of Cat - Cat, of course!
print type(jas)
# Is the type Cat, itself, an instance of some type? - Yes!
print type(Cat)
# What is the type of Cat's superclass, object?
print type(object)
# What is the type of the built in type float?
print type(float)
# Is a method a type of something?
print type(Cat.__init__)
# Is a built in function a type of something?
print type(len)

Output ...

<type 'int'>
<type 'float'>
<type 'list'>
<type 'dict'>
<class 'Cat'>
<type 'type'>
<type 'type'>
<type 'type'>
<type 'instancemethod'>
<type 'builtin_function_or_method'>


@leonhard.wettengmx.n, @appylpye,

Thank you guys loads for bothering with these conceptual questions :slight_smile: I will slowly read the links after I finish the Introduction to Classes and Classes exercises. Thanks again!