くろまる社長 「python」学習日記 2020-07-02
2020-06-27
今日やったことリスト(座学)
- クラス継承とは
- メソッドとは
- 新旧クラススタイルとは
- クラスとは
学んだこと
- クラスとは
データ構造をつくるしくみ
※具体例
鯛焼き機→鯛焼きに中身を入れる→鯛焼きを焼く
(クラス) (インスタンス化) (インスタンス)
※参考サイト
https://aiacademy.jp/media/?p=131 - クラス継承
存続のクラスから新規作成したクラスに
変数定義や、メソッドを引き継ぐこと
※参考サイト
https://www.sejuku.net/blog/9598 - 新旧クラススタイルとは
オブジェクトを継承したクラス→新クラス
なにも継承しないクラス →旧クラス
※新旧クラスの違いがあるのはpython2系での話
※参考サイト
http://ichitcltk.hustle.ne.jp/gudon2/index.php?pageType=file&id=python_class_style.md#:~:text=%E6%96%B0%E3%82%B9%E3%82%BF%E3%82%A4%E3%83%AB%E3%81%AE%E3%82%AF%E3%83%A9%E3%82%B9%E3%81%AB,%E3%82%B9%E3%82%BF%E3%82%A4%E3%83%AB%E3%81%AE%E3%82%AF%E3%83%A9%E3%82%B9%E3%81%A8%E5%91%BC%E3%81%B6%E3%80%82
- メソッドとは
クラスに定義された関数のこと
※参考サイト
https://aiacademy.jp/media/?p=131
調べたこと
- [Sy] Visual Studio Code 内でターミナルを起動するショートカット(Mac)
https://utano.jp/entry/2018/01/visual-studio-code-terminal-window/
- Pythonのタプルとは一体?わかりやすく解説をしてみた
https://blog.codecamp.jp/python-tuple
- Pythonにおける複数行コメントの記述方法を現役エンジニアが解説【初心者向け】
https://techacademy.jp/magazine/30589
- [Python]kwargsの読み方って?【クワーグス】
https://yuki.world/kwargs-how-to-pronounce/
- "u"と "r"の文字列フラグは正確に何をしますか、そして生の文字列リテラルとは何ですか?
https://www.it-swarm.dev/ja/python/quotuquot%E3%81%A8-quotrquot%E3%81%AE%E6%96%87%E5%AD%97%E5%88%97%E3%83%95%E3%83%A9%E3%82%B0%E3%81%AF%E6%AD%A3%E7%A2%BA%E3%81%AB%E4%BD%95%E3%82%92%E3%81%97%E3%81%BE%E3%81%99%E3%81%8B%E3%80%81%E3%81%9D%E3%81%97%E3%81%A6%E7%94%9F%E3%81%AE%E6%96%87%E5%AD%97%E5%88%97%E3%83%AA%E3%83%86%E3%83%A9%E3%83%AB%E3%81%A8%E3%81%AF%E4%BD%95%E3%81%A7%E3%81%99%E3%81%8B%EF%BC%9F/968305156/
- VS Codeで指定範囲をコメントにしたり戻したりするには
https://blog.hatena.ne.jp/kuromaru0913/kuromaru0913.hatenablog.com/edit
今日やったコード一覧
- class_file.py
- class_file0.py
class Country:def __init__(self, country_name):self.country_name = country_name
class City(Country):def __init__(self, country_name, city_name):super().__init__(country_name)self.city_name = city_name
classes =classes.append(City('Japan','Tokyo'))classes.append(City('USA', 'Washington, DC'))
for country_city in classes:print('=== Class ===')print('country_name -->' + country_city.country_name)print('city_name -->' + country_city.city_name) - class_file1.py
""" #親スタイルクラスclass NewStyleClassBase(object):def test_method(self, msg):print('NewStyleClassBase: {}'.format(msg))#新スタイルのクラス継承class NewStyleClass(NewStyleClassBase):def test_method(self, msg):print('NewStyleClass: {}'.format(msg))super().test_method(msg)new = NewStyleClass()new.test_method('method call') """
"""#親スタイルクラスclass NewStyleClassBase:def test_method(self, msg1, msg2):print('NewStyleClassBase_No1: {} NewStyleClassBase_No2: {}'.format(msg1,msg2))#新スタイルのクラス継承class NewStyleClass(NewStyleClassBase):def test_method(self, msg1, msg2):print('NewStyleClass_No1: {} NewStyleClass_No2: {}'.format(msg1,msg2))super().test_method(msg1, msg2)new = NewStyleClass()new.test_method('method call', 'method calls') """
"""#親スタイルクラスclass NewStyleClassBase(object):def __init__(self, msg):self.msg = msgprint('NewStyleClassBase: {}'.format(msg))#新スタイルのクラス継承class NewStyleClass(NewStyleClassBase):def __init__(self, msg):self.msg = msgprint('NewStyleClass: {}'.format(msg))super().__init__(msg)NewStyleClass('method call') """
val = 100def ham(self):self.egg('call method')
def egg(self,msg):print("{0}".format(msg))print(("{0}".format(self.val)))
spam.ham()