Python memo

Object-oriented contrast with C ++

Class inheritance

subclass.py


#!/usr/bin/env python
# -*- coding: utf-8 -*-

class Base(object):
    def __init__(self):
        self.name = "Base"

    def echo(self):
        self.hello()
        print("name = {}".format(self.name))
        self._underscore1_func()
        self.__underscore2_func()

    def hello(self):
        print("My class is Base.")

    def _underscore1_func(self):
        print("Base::_underscore1_func()")

    def __underscore2_func(self):
        print("Base::__underscore2_func()")

class Deriv(Base):
    def __init__(self):
        super().__init__()
        self.name = "Deriv"

    def hello(self):
        print("My class is Deriv.")

    def _underscore1_func(self):
        print("Deriv::_underscore1_func()")

    def __underscore2_func2(self):
        print("Deriv::__underscore2_func()")


if __name__ == '__main__':
    print(">>>> Base object")
    a = Base()
    a.echo()
    print()

    print(">>>> Deriv object")
    b = Deriv()
    b.echo()
>>>> Base object
My class is Base.
name = Base
Base::_underscore1_func()
Base::__underscore2_func()

>>>> Deriv object
My class is Deriv.
name = Deriv
Deriv::_underscore1_func()
Base::__underscore2_func()

Recommended Posts

python memo
Python memo
python memo
Python memo
Python memo
Python memo
[Python] Memo dictionary
python beginner memo (9.2-10)
python beginner memo (9.1)
★ Memo ★ Python Iroha
[Python] EDA memo
[My memo] python
Python3 metaclass memo
[Python] Basemap memo
Python beginner memo (2)
[Python] Numpy memo
Python class (Python learning memo ⑦)
python openCV installation (memo)
Python module (Python learning memo ④)
Visualization memo by Python
Python
Python test package memo
[Python] Memo about functions
python regular expression memo
Binary search (python2.7) memo
[My memo] python -v / python -V
Python3 List / dictionary memo
[Memo] Python3 list sort
Python Tips (my memo)
DynamoDB Script Memo (Python)
Python basic memo --Part 2
python recipe book Memo
Basic Python command memo
Python OpenCV tutorial memo
Python basic grammar memo
TensorFlow API memo (Python)
python useful memo links
Python decorator operation memo
Python basic memo --Part 1
Effective Python Memo Item 3
Divisor enumeration Python memo
Python memo (for myself): Array
Python exception handling (Python learning memo ⑥)
Python execution time measurement memo
[Line / Python] Beacon implementation memo
Python Basic Grammar Memo (Part 1)
Python code memo for yourself
Raspberry Pi + Python + OpenGL memo
Python basic grammar (miscellaneous) Memo (3)
Python memo using perl --join
Python data type summary memo
Python basic grammar (miscellaneous) Memo (2)
[MEMO] [Development environment construction] Python
[Python] virtualenv creation procedure memo
Python basic grammar (miscellaneous) Memo (4)
Regarding speeding up python (memo)
Python control syntax, functions (Python learning memo ②)
Raspberry-pi memo
Pandas memo
Python basics ⑤
python + lottery 6