in Technology by
What are global, protected and private attributes in Python?

1 Answer

0 votes
by
  • Global variables are public variables that are defined in the global scope. To use the variable in the global scope inside a function, we use the global keyword.
  • Protected attributes are attributes defined with a underscore prefixed to their identifier eg. _sara. They can still be accessed and modified from outside the class they are defined in but a responsible developer should refrain from doing so.
  • Private attributes are attributes with double underscore prefixed to their identifier eg. __ansh. They cannot be accessed or modified from the outside directly and will result in an AttributeError if such an attempt is made.

Related questions

0 votes
    DAM architecture in which a lightweight sensor is attached to the protected databases and continuously polls the ... (3)Interception-based architecture (4)Network Architecture...
asked May 19, 2021 in Technology by JackTerrance
0 votes
    Which of these class allows us to get real time data about private and protected member of a class? (a) java. ... & Packages of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    _______ mechanisms ensure that information contained in objects does not flow explicitly or implicitly into less protected ... Inference control (2)Access control (3)Flow control...
asked Jun 1, 2021 in Technology by JackTerrance
0 votes
    When using ASP.NET protected configuration, how can I encrypt the config with just the public key? I can ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
0 votes
    (FWIW, I've posted this question to my blog as well: http://blog.wolffmyren.com/2011/07/11/ie- ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I need to cast a class to its protected base: class ComplicatedOne : public Object { //Lots of ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    Which is a valid declaration within an interface? A)protected short stop = 23; b)final void madness(short stop); ... (double duty);? Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
0 votes
    A _____________ attack one of the simplest processes of gaining access to any password-protected system. (a) ... -Cyber Security:,Cyber Security-Jobs:,Cyber Security Applications...
asked Nov 1, 2021 in Education by JackTerrance
0 votes
    Which of the following online services' privacy cannot be protected using Tor? (a) Instant messaging (b) ... for-Cyber Security:,Cyber Security-Jobs:,Cyber Security Applications...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    What is true about protected constructor? (a) Protected constructor can be called directly (b) Protected ... questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    How can a protected modifier be accessed? (a) accessible only within the class (b) accessible only within ... questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    Can a class be declared with a protected modifier. (a) True (b) False This question was posed to ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    A class member declared protected becomes a member of subclass of which type? (a) public member (b) ... questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
...