Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

4. Separate Public, Protected and Private Attributes

Sumit Rawal answered on May 13, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • private public internal protected kotlin
  • c# private public
  • java protected private public
  • Class access modifiers. public private protected what is it. Access Specifiers
  • Difference between Public, Private and Protected modifier in Java?
  • Public and private Subnets
  • what is public private and protected as together called
  • Public properties can be created via Instance public fields
  • Public properties can be created via Static public fields
  • Does Java allow us to use private and protected modifiers for variables in interfaces?
  • Private attributes#
  • Accessing private attributes in the main code#
  • Private and Public Fields#

  • 4. Separate Public, Protected and Private Attributes

    0

    Unlike C++ or Java, Python doesn’t have strict restrictions for the permissions of attributes.

    The Pythonic way to separate different permissions is to use underscores:

    As the above code shows, we can define a protected attribute with a single leading underscore. This is just a convention. We can still use it as a public member. But we should not do this. Following good programming conventions will make our code more elegant and readable.

    We define a private attribute with double-leading underscores. This mechanism is beyond convention. Python uses name mangling technique to ensure we won’t use a private member inappropriately.

    Popularity 1/10 Helpfulness 1/10 Language python
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on May 13 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.