Professional Documents
Culture Documents
Chapter3 Utilizing Classes
Chapter3 Utilizing Classes
Package
S O F T WA R E E N G I N E E R I N G F O R D ATA S C I E N T I S T S I N P Y T H O N
Adam Spannbauer
Machine Learning Engineer at Eastman
Object oriented programming
working in work_dir/my_script.py
import my_package
Adam Spannbauer
Machine Learning Engineer at Eastman
Extending Document class
class Document:
def __init__(self, text):
self.text = text
['test', 'doc']
Unpredictability
Adam Spannbauer
Machine Learning Engineer at Eastman
Creating a SocialMedia Class
Adam Spannbauer
Machine Learning Engineer at Eastman
Creating a Tweet class
class Child(Parent):
def __init__(self):
Parent.__init__()
print("I'm a child!")
class SuperChild(Parent):
def __init__(self):
super().__init__()
print("I'm a super child!")
class SuperChild(Parent):
def __init__(self):
super().__init__()
print("I'm a super child!")
class Grandchild(SuperChild):
def __init__(self):
super().__init__()
print("I'm a grandchild!")
grandchild = Grandchild()
I'm a parent!
I'm a super child!
I'm a grandchild!