-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoop.py
More file actions
38 lines (30 loc) · 964 Bytes
/
oop.py
File metadata and controls
38 lines (30 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
"""
Created on Tue May 17 16:15:37 2022
@author: user
"""
#OOP
class Animal:
#self refer to class attr
def __init__(self, gender, name, age):
self.gender = gender
self.name = name
self.age = age
def toString(self):
print('%s %s is %d' %(self.gender, self.name, self.age))
#INHERITANCE
class Mammal(Animal):
#This overrides the parent
def __init__(self, gender, name, age, skin):
super().__init__(gender, name, age)
#add child attrs
self.skin = skin
#*arbitary args == varags/variadic func
def mammalKids(self, *kids):
print('%s has 3 kids: %s %s %s' %(self.name, kids[0], kids[1], kids[2]))
def printMammal(self):
print(f'this is mammal: {self.skin}, {self.gender}, {self.name}')
#JSON
#dumps() : convert python to json.
#loads() : convert json to python.
#https://www.w3schools.com/python/python_json.asp