Last active
February 12, 2022 18:35
-
-
Save StephenFordham/6f0fcfdaaf1916628f2a210f3b81ac72 to your computer and use it in GitHub Desktop.
Example_2_using_classes.py
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
class StrAttrValidation(object): | |
def __init__(self): | |
self._dict = dict() | |
def __set__(self, instance, value): | |
self._dict[instance] = value.title() | |
def __get__(self, instance, value): | |
return self._dict[instance] | |
class Employees(object): | |
name = StrAttrValidation() | |
location = StrAttrValidation() | |
def __init__(self, name, location): | |
self.name = name | |
self.location = location | |
emp1 = Employees('stephen', 'bournemouth') | |
print(emp1.name) | |
print(emp1.location) | |
#Terminal Output | |
Stephen | |
Bournemouth |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment