2
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のあんまり知らなそうな組み込み関数、変数、メソッド集 #4 [copyright, credits, __debug__]

2
Posted at

昨日は記事をもう一つ書くと言っておきながらできなくてすみません...
#3はこちら


copyright

コピーライトを表示します。
本来対話型のターミナルで使う用なのですが、コード内でも普通に呼び出せます。
printや実行をすることで以下の文章が表示されます。
(__repr____call__が定義されているため)
ちなみにこれを調べたら_sitebuiltins_Printerという
オブジェクトらしいです。

Copyright (c) 2001-2024 Python Software Foundation.
All Rights Reserved.

Copyright (c) 2000 BeOpen.com.
All Rights Reserved.

Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.

Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved.

credits

さっきとほぼ同様ですが、表示されるのがクレジットです。

    Thanks to CWI, CNRI, BeOpen, Zope Corporation, the Python Software
    Foundation, and a cast of thousands for supporting Python
    development.  See www.python.org for more information.

debug

大体の場合はTrueになっていますが、

python -O

という感じでOptimizationオプションを使用すると
コードの最適化が行われて__debug__Falseに切り替わります。
ちなみにこれがFalseだとassert文が実行されません。


組み込みのオブジェクトを調べるとPythonの
あまり知られていない機能がわかることもあります。
最後まで読んでいただきありがとうございます!

2
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
2
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?