Answer:
class Dog:
"""A dog with name and breed."""
def __init__(self, name, breed):
self.name = name
self.breed = breed
import dog
if __name__ == '__main__':
sugar = dog.Dog('sugar', 'border collie')
print(sugar.name)
print(sugar.breed)
Step-by-step explanation:
CLASS: A class describes what an object will be, it contains methods of functions and it is defined by using the key word class.
class Dog:
#The class is defined
Docstring: It is a short form of documentation strings, it provides a convenient way of associating documentation with Python modules, functions, classes, and methods. i.e, it tells you what they do.
it is declared by using triple quotes.
"""A dog with name and breed."""
Next we define the method and and assign attributes (Name and Breed) to the class.
def __init__(self, name, breed):
self.name = name
self.breed = breed
we import the class next: to do this ensure that you save your source file with the name dog.
Finally, we print out its attributes.
import dog
if __name__ == '__main__':
sugar = dog.Dog('sugar', 'border collie')
print(sugar.name)
print(sugar.breed)
I have attached a picture for you to see how the code runs