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

3
Posted at

前回の話

前回str.capitalize, int.bit_count, Exception.add_noteを紹介しました!
これはその続きの記事です!

import

何かを動的にインポートすることができます!

print(__import__("builtins").print == print) # True

builtins

builtinsを変数として参照できます!さっきの__import__と似ています。

print(__builtins__.print == print) # True

doc

ファイルのDoc stringを取得することができます。

"""
This file is example.
"""
print(__doc__) # This file is example.

def func():
    """
    func
    """
    pass

print(func.__doc__) # func

関数でも取得可能!


まだまだPythonには隠れた関数や変数があると思います!
今後もこのシリーズは続けていこうと思います!

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