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: | |
def __init__(self, number): # magic method / inititalizer | |
print( "The Phone object was created" ) | |
self.number = number | |
def __lt__(self, other): # magic method / rich comparison | |
return self.number < other.number |
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 | |
__serial_number = "11.22.33" # private variable | |
__how_many_times_turned_on = 0 # private variable | |
def call(self): # public method | |
print( "Ring-ring!" ) |
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 |
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: | |
number = "111-11-11" | |
def print_number(self): | |
print( "Phone number is: ", self.number ) | |
my_phone = Phone() | |
my_phone.print_number() |
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 | |
__serial_number = "11.22.33" # private variable | |
__how_many_times_turned_on = 0 # private variable | |
def __init__(self): # constructor | |
print( "The Phone object was created" ) | |
self.__turn_on() |
NewerOlder