#Python basics (class)

1. Class

constructor



#### **`instance`**
```self      


 * Self is indispensable in the design specifications of python. It is possible to use a keyword other than "self" for the name (for example, myself), but it is customary to use self.
 [Reference page](https://www.sejuku.net/blog/64106)

class Calc: def init(self, a): #constructor self.a = a

def add(self, b):
    print(self.a + b)
    
def multiply(self, b):
    print(self.a * b)

calc = Calc(10) calc.add(10) calc.multiply(10)



#### **`Execution result`**
```python

20
100

2. Inheritance

class Calc:
    def __init__(self, a): #constructor
        self.a = a
   
    def add(self, b):
        print(self.a + b)
        
    def multiply(self, b):
        print(self.a * b)

CalcExtends, a class that inherits from the Calc class

class Child class name (parent class)

class CalcExtends(Calc):     #Inherit Calc
    def subtract(self, b):
        print(self.a - b)
        
    def divide(self, b):
        print(self.a / b)
calc_extends = CalcExtends(3)
calc_extends.add(4)
calc_extends.multiply(4)
calc_extends.subtract(4)
calc_extends.divide(4)

Execution result


7
12
-1
0.75

Recommended Posts

#Python basics (class)
Python basics ⑤
Python basics ④
Python basics ③
Python basics
Python basics
Python basics
Python basics ③
Python basics ②
[Python] class, instance
Python basics: list
Python basics memorandum
"Kanrika" python class
About python, class
#Python basics (#matplotlib)
Python basics: dictionary
Basics of Python ①
Basics of python ①
Python slice basics
#Python basics (scope)
Go class basics
#Python basics (#Numpy 1/2)
Python array basics
Python class, instance
Python profiling basics
Python #Numpy basics
Python basics summary
[Learning memo] Basics of class by python
python syslog wrapper class
Python class (Python learning memo ⑦)
case class in python
Python: Unsupervised Learning: Basics
Basics of Python scraping basics
[Python] Class inheritance (super)
Python basics 8 numpy test
[python] class basic methods
Errbot: Python chatbot basics
[Python] Class inheritance, override
#Python DeepLearning Basics (Mathematics 1/4)
Python basics: Socket, Dnspython
python subprocess wrapper class
# 4 [python] Basics of functions
Basics of python: Output
YOLO Python wrapper class
Class notation in Python
Python exception class list
Python: Class and instance variables
Python
C / C ++ programmer challenges Python (class)
class
Python class member scope summary
python: Basics of using scikit-learn ①
Python class variables and instance variables
Python basics: conditions and iterations
Paiza Python Primer 4: List Basics
class
Basics of Python × GIS (Part 1)
Basics of Python x GIS (Part 3)
How to write a Python class
Paiza Python Primer 5: Basics of Dictionaries
SNS Python basics made with Flask