Lesson 10 Flashcards

1
Q

Libraries/modules

A

A python module is a reusable collection of functions, variables, and code that can be imported into a program to extend its functionality
Modules provide a structured and efficient way to share reusable code with others

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why are modules good

A

Maintainability: updates and improvements can be made to a module without modifying the main program.
Modularity: Enabling independent development and debugging of different parts of a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Creating a module:

A

Write function definitions and variables in a file and save it with the *.py extension

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Using a module

A

There are multiple ways to import a module to gain access to the functions/variables within it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Importing a module

A

Import list_processor
import list_processor as lp #alias
from list_processor import sum_all, LIST_OF_ZERO #specific functions/ variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Importing multiple modules:

A

in case there are name conflicts with functions/variables imported from multiple modules you should rename them at the time of import

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Changing names at import

A

from another_module import sum_all as sum_all2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Circular imports

A

When two modules depend on each other

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Running a script bs importing a script:

A

Any *.py file is considered a script but some are intended ti be modules and other programs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Every python script has a special built in variable called:

A

__name__

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When a script runs directly, __name__ is set to

A

“__main__”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

When a script is imported as a module, __name__

A

is set to the modules filename

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

To promote reusability in scripts

A

it is best practice to separate script logic and library code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Built in modules:

A

these come pre installed with python and can be directly imported using the methods introduced

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Common built in modules

A

math- extends the list of mathematical functions
sys- provides access to system specific parameters and functions, allowing interaction with the python runtime environment (sys.argv, e.g.)
os-interact with the operating system (manage files and folders, e.g)
random: make random numbers
datetime: create dates

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

External modules: these have to be installed

A
  • In a terminal window, type ‘pip install <module>’
    Typically pip is pre installed when Python is installed. If it is not, use Google/chatGPT to help you install pip</module>
17
Q

numpy

A

Used for working with arrays/matrices

18
Q

Matplot lib

A

used for plotting data

19
Q

Sklearn

A

machine learning