Class - Object


#1



class Animal(object):
    def __init__(self,name):
        self.name = name
        
    
    
zebra = Animal("Jeffrey")

print zebra.name


Can anybody help me understand the code how it works as i am new to programming


Replace this line with your code.


#2

a class is like a blue print, it describe something. In this case, an animal.

in this case, your animal has a name. When you create a class instance:

zebra = Animal("Jeffrey")

you create an actual animal with a name. When creating a class instance, the init() method is called


#3

Thank you , got that

Ex :Dog is a class , bark is a method and Pomeranian is an instance of Class (Dog)


#4

yes, indeed :slight_smile: Well done :slight_smile:


#5

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