【Python】分享一個令人哭笑不得的bug,Python類實例化無法調用初始化函數?

話不多說,直接上代碼!!!

class sportsman:
    def __int__(self):
        print("預備!")

    def run(self):
        print("跑!")


def main():
    sportsman().run()


if __name__ == "__main__":
    main()

摸摸你們自己的良心,有多少人像我一樣,一本正經的認爲輸出應該是這樣的

預備!
跑!

然而,現實很殘酷,“預備”不見了

跑!

那時候的我,一個人靜靜地在風中凌亂了,甚至開始懷疑Python類實例化的時候不會自動調用初始化函數~~


直到~~~

某個陽光明媚的午後,我猛然發現了真相,告辭!!!我需要一個人靜靜。。。

在這裏插入圖片描述


祝看到此文的道友,漫漫長路,少一些bug~~

"""
    Code is far away from bugs with the god animal protecting.
    I love animals. They taste delicious.
               ┏┓     ┏┓
              ┏┛┻━━━━━┛┻ ┓
              ┃          ┃
              ┃  ┳┛  ┗┳  ┃
              ┃    ┻     ┃
              ┗━┓      ┏━┛
                ┃      ┗━━━┓
                ┃  神獸保佑 ┣┓
                ┃  永無BUG!┏┛
                ┗┓┓┏━  ┳┓┏┛
                 ┃┫┫   ┃┫┫
                 ┗┻┛   ┗┻┛
"""
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章