What is a class?


#1

Help, I’m having trouble trying to understand what a class does and what the point of them is. Inheritance, “super()” and bases confuse me also. A simplified explanation would be great, as I really dont know anything that’s going on. I’ve made it to exercise 14 but the introduction of super() and bases have thrown me off.

<do not remove the three backticks above>

#2

such explanation are very time consuming to write, thankfully people do from time to time:

as mentioned in this guide:

class is used to define a class. And what is a class? Simply a logical grouping of data and functions

classes are powerful, but a bit confusing at first

when it comes to inheritance, classes can inherit data from parent class, the absolute simplest example:

class Parent(object):
    pass

class Child(Parent):
   pass

now Child class inherit all data (methods, member variable) from Parent class

super() allows use to call parent parent method, so for example:

class Parent(object):
    def hello_world(self):
        print "hello world"

class Child(Parent):
   def call_parent_method(self):
       super(Child, self).hello_world()

now call_parent_method method calls the hello_world method of Parent class


#3

thanks! I understand it a lot more now!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.