Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,032 questions

9,976 answers

573 users

How to add Data Abstraction (Data Encapsulation & Hiding) with two methods for attributes in Python

1 Answer

0 votes
class Test:
    def __init__(self, language=None):
        self.language = language

    def method(self):
        if self.language:
            print("L: " + self.language)
        else:
            print("Language is empty")

    def set_language(self, language):
        self.language = language

    def get_language(self):
        return self.language


o1 = Test()
o1.set_language("Python")
o1.method()

o2 = Test()
o2.set_language(o1.get_language())
print(o2.get_language())


'''
run:
 
L: Python
Python
 
'''

 




answered Feb 8 by avibootz
...