How do I add a member variable to the Triangle class?


#1

Question

How do I add a member variable to the Triangle class?

Answer

Recall that a member variable is one that’s inside of a class and available to all methods within that class, meaning it’s outside of the methods but inside of the class. So be sure to indent the member variable to 2 spaces so it’s inside the class, like this:

class MyClass(object):
  my_member_var = 10  # My member variable!

  def __init__(self):
    pass

FAQ: Learn Python - Introduction to Bitwise Operators - Class It Up