Last active
March 5, 2019 10:40
-
-
Save kateolenya/16698fc6a5a04783bc3f7190fb9b00bc to your computer and use it in GitHub Desktop.
Basic encapsulation in Python3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
class Phone: | |
username = "Kate" # public variable | |
__how_many_times_turned_on = 0 # private variable | |
def call(self): # public method | |
print( "Ring-ring!" ) | |
def __turn_on(self): # private method | |
self.__how_many_times_turned_on += 1 | |
print( "Times was turned on: ", self.__how_many_times_turned_on ) | |
my_phone = Phone() | |
my_phone.call() | |
print( "The username is ", my_phone.username ) | |
input( "Press Enter to exit" ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment