What is the scope of the variable hardness?
class pencil:
color = 'yellow'
hardness = 2
class pencilCase:
def __init__(self, color, art):
self.color = 'black'
self.art = 'wolf'
def __str__(self):
return self.color + " " + self.art
# main part of the program
pencilA = pencil()
limited to the pencilCase class
accessible to all parts of the program
limited to the pencil class
limited to the main part of the program

See Answers (1)

Suggested Answer

Answer:The variable petName is local to the class; This isdue to the fact that the variable was created in a function whose name begins with two underscores.The variable color; This is created in the petCarrier class and is accessible to the entire function. This was not created in a function whose name begins with an underscore.Explanation:

Related Question in Computers and Technology