1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Pythonのあんまり知らなそうな組み込み関数、変数、メソッド集 #6 [object.mro, quit.eof, breakpoint]

1
Last updated at Posted at 2025-12-24

前回はこちら。
今回は久しぶりにメソッドを多めに持ってきましたよ!

object.mro

class ParentClass: ...
class ChildClass(ParentClass): ...

print(ChildClass.mro())
# [<class '__main__.ChildClass'>, <class '__main__.ParentClass'>, <class 'object'>]

クラスの継承されている順番を見ることができます。
家系図みたいで面白いですね!

quit.eof

# macOSの場合
print(quit.eof) # Ctrl-D (i.e. EOF)

Pythonを停止させるときに使うショートカットキーがわかるようです!

print(f"終了するには'{quit.eof.split()[0]}'を押してください。")

こんな感じで使うとユーザーに対して、プログラムを
終了する方法を明記できるので便利かもしれません!
(ちなみに、exit.eofも同様です)

breakpoint

その名の通り、ブレークポイントが作れます。

score = 0
breakpoint()
print(f"得点は{score}点です")

これを実行すると、

> hoge.py(3)<module>()
-> breakpoint()
(Pdb) a=100    # 代入
(Pdb) continue # プログラム続行
100

こんな感じで、途中で変数を操作したりすることができます!


ブレークポイントって、もう少し複雑なイメージがありましたが、
エディタに頼らずPythonだけで実装することもできるんですね!
最後まで読んでいただきありがとうございます!

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?