@@ -0,0 +1,2105 @@
+#myDog = Dog(%22Fluffy%22,%22Poodle%22,%22White%22) ## It is an object of type Dog. Dog is the class.%0A                                       ## myDog is a local variable. It can be named anything,%0A                                       ## it is just a label attached to some object.%0A                                       ## Dog create an instance of class Dog, will call the __init__ method implicitly.%0A                                       ## %22Fluffy%22, %22Poodle%22, %22White%22 the parameters to pass to the __init__ method.%0A%0Aclass Dog:%0A    def __init__(self, name, breed, colour):%0A        #set attributes%0A        self.name = name%0A        self.breed = breed%0A        self.colour = colour%0A        ## This creates a Dog object by calling the __init__ function in the Dog class.%0A        ## In this method you should set the data attributes,%0A        ## or instance variables (the traits %22global%22 to every dog),%0A        ##Each class has one __init__ function, but may have many instance variables.%0A        ## Now the behaviour is specified by methods within the class specification.%0A%0A    def bark(self):%0A        print(%22%7B%7D barks!%22.format(self.name))%0A        ##The behaviour is specified by methods within the class specification.%0A%0Adog1 = Dog(%22Fluffy%22, %22Poodle%22, %22White%22)  ## Here can get some multipies dogs.%0Adog2 = Dog(%22Lassie%22, %22Collie%22, %22Brown, dark streaks with white chest%22)%0Adalmatians = %5B%5D%0Afor i in range(0,101):%0A    dalmatians.append(Dog(i,%22Dalmatian%22,%22White with black spots%22))%0A%0A%0A## When you call a method of an object self is passed in implicitly%0A## and is the object you're calling the method on.%0A## For example, myDog.bark() does the same thing as Dog.bark(myDog).%0A##When using Dog(%22Fluffy%22, %22Poodle%22, %22White%22) to create a new dog,%0A##things are a bit trickier. __init__ can't be called straight away with self%0A##because self doesn't exist yet. Python actually uses a different class method,%0A##  __new__, to create a new object, then passes this newly created object as the self parameter to __init__,%0A## which initialises the object. You can override the __new__ method if you want but that's hardly ever necessary.%0A%0A

Add files via upload