214k views
4 votes
QUICK 100!!!!

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
limited to the pencilCase class

accessible to all parts of the program
accessible to all parts of the program

limited to the pencil class
limited to the pencil class

limited to the main part of the program

User Mkisantal
by
7.7k points

1 Answer

0 votes

Answer:

The variable "hardness" is limited to the "pencil" class

Step-by-step explanation:

As we can see in the program - the line where the variable "hardness" is declared and defined is set under the instruction "class pencil:" which is the python syntax keyword for defining a class

Python uses indentation as a way of declaring scopes and in your example no indentation is used, that's why I'm making an assumption "pencil" belongs to class "pencil".

Next time please use indentation. :))

User Nels
by
7.7k points