How would you define a class attribute that should not be overridden by subclasses?

  • Declare it as a constant
  • Declare it as a static method
  • Prefix it with an underscore (_)
  • Use the @final decorator
To define a class attribute that should not be overridden by subclasses, prefix it with an underscore (_). While Python doesn't enforce strict encapsulation, this convention signals to other programmers that the attribute should not be modified.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *