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?

More than 5 years have passed since last update.

Python:モジュールについて(超基礎)

Last updated at Posted at 2018-01-16

モジュールとは?

  1. Pythonインタプリタを終了させる
  2. 再び起動すると,これまでの定義は失われる

面倒だ!

  • Pythonでは定義を.pyファイルに書いておき,スクリプトの中や,インタプリタの対話インスタンス上で使う!
  • この.pyファイルをモジュール(module)と呼ぶ.

モジュールのインポート(モジュールを使う)方法

  • ある関数を定義したモジュールをmodule.pyとする
  • コードでは,import moduleと書いてmoduleモジュールを呼び出す(拡張子の.pyはいらない)
  • あとは,関数を使うだけ!

まとめ:

  1. よく使う関数はファイルに保存し,それを呼び出して使う
  2. モジュールはPythonの定義や文が入ったファイル
  3. ファイル名はモジュール名に接尾語.pyが付いたもの
  4. import モジュール名でモジュールが呼び出せる

とりあえず,ここまでが導入です.

1
1
2

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?