Creating an Instance of a Class in Python

How can you create an instance of the pet class in Python?

Which line of code will correctly create an instance of the pet class as defined below?

class pet:
def __init__(self,strSpecies,strName):
self.species = strSpecies
self.petName = strName

A) myPetA = pet('dog', 'Spot')

B) myPetA = pet(self, 'dog', 'Spot')

C) myPetA = new pet('dog', 'Spot')

D) myPetA .pet() = 'dog', 'Spot'

Answer:

myPetA = pet(self, 'dog', 'Spot')

The correct line of code that will create an instance of the pet class is myPetA = pet(self, 'dog', 'Spot'). Option B is correct.

← Convert acres to hectares with python What is the value of the larger addend when the sum of two numbers is 7038 →