0
0

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 1 year has passed since last update.

Python 3 エンジニア認定基礎試験対策6 - モジュール

0
Last updated at Posted at 2024-01-23

はじめに

Python3エンジニア認定基礎試験の対策として自分用に執筆しています。

この記事はPython・執筆学びたての初心者が執筆しています。間違いがあるかもしれませんので、ぜひ各項目にある参考文献も確認してください。また、誤りがあればコメントで教えていただけると幸いです。

モジュール

Pythonの定義や分が入ったファイルをモジュールという。

>>> import math # mathモジュールをインポート
>>> print(math.fabs(-1) # mathモジュールの絶対値を返す関数を呼び出し
1.0
>>> fab = math.fabs # 関数を変数にいれる
>>> print(fab(5)
5.0

fromを利用してモジュールで定義されている関数を取り入れることができる

>>> from random import randint
>>> print(randint(1, 10))
6

標準で同梱しているモジュールを標準モジュールという。sysなど。
dir()関数はモジュールが定義した名前を調べるために使う。

パッケージ

Pythonのモジュール名前空間を ドット付きモジュール名 を使って構造化する手段。

A.BはパッケージAのサブモジュールBを意味する。

__init__.pyファイルはパッケージをファイルシステム上で認識させるために使う。

参考文献

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?