Chapter 12: Python Engineering Modules: Imports, Packages, and pip

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/26

encourage image

There's no tags or description

Looks like no tags are added yet.

27 Terms

1
New cards

What are modules in Python?

Modules are collections of Python code that someone else wrote, often stored in a single file.

2
New cards

What is a package in Python?

A package is a collection of related modules.

3
New cards

How do you import a whole module in Python?

Use the command: import .

4
New cards

What is the syntax to call a function from an imported module?

.().
5
New cards

How can you import individual functions from a module?

Use the command: from import .

6
New cards

What happens when you import all functions from a module using *?

You bring in all functions, but it can cause conflicts with existing functions.

7
New cards

What is the command to import all functions from a module?

from import *.

8
New cards

What is an example of importing a specific function from a module?

from math import sqrt.

9
New cards

What is the purpose of the math module in Python?

It provides functions for mathematical operations, such as sin and sqrt.

10
New cards

How do you rename a function when importing it?

Use the syntax: from import as .

11
New cards

What is the command to display available functions in a module?

Use: import as m; print(dir(m)).

12
New cards

How can you access documentation for a function in a module?

Use: help(.).

13
New cards

What is pip used for?

Pip is a routine for installing Python packages.

14
New cards

What command do you use to install a package with pip?

pip install .

15
New cards

What is the Python Package Index?

A repository of registered packages/modules available for Python.

16
New cards

What is the difference between a module and a library?

A module is a single file of code, while a library is a collection of modules.

17
New cards

What is the recommended way to import the numpy and matplotlib packages?

import numpy as np; import matplotlib.pyplot as plt.

18
New cards

What is the purpose of the numpy package?

It is used for performing vector and matrix operations.

19
New cards

What is the purpose of the matplotlib package?

It is used for creating data plots.

20
New cards

What should you do before installing a new module?

Read the documentation to understand how it works.

21
New cards

What is an example of a built-in module in Python?

math, cmath, or random.

22
New cards

What is the command to create a linear space in numpy?

np.linspace(start, stop, num).

23
New cards

How do you plot data using matplotlib?

Use plt.plot(x, y) followed by plt.show().

24
New cards

What is a common issue when importing all functions from a module?

You may unintentionally overwrite existing functions.

25
New cards

What is the significance of the init.py file in a package?

It indicates that the directory should be treated as a package.

26
New cards

What is a submodule?

A module that is part of a package, accessed using ..

27
New cards

What does the command 'import math' do?

It imports the entire math module, making its functions available.