Python Fundamentals · Getting started
19 cards
A Python Development Workflow
-
Quick check
Before writing any code, which three things settle what shape the program should take?
AThe input, the wanted output, and how often the work must be repeated
Right. The problem determines the code and the libraries needed, so the input, the desired output and the repeatability need are written down first.
BThe launcher name used on your operating system
Launcher names vary by platform and installation, and they say nothing about what the program has to do.
CWhich community packages happen to be installed in the environment already
Installed packages are a later question; the task decides which capability is needed in the first place.
2 / 19
-
Quick check
You are unsure how one expression behaves and want the answer now. Which mode fits?
AA saved script, run again after each edit
A script is the right home for repeatable work, but it adds a save-and-run step to a one-line question.
BA module copied into several programs
Copying code into several programs is the duplication that modules exist to prevent, and it answers nothing about the expression.
CInteractive mode, where the interpreter reads and executes commands as they are typed
Right. When its standard input is connected to a terminal, the interpreter reads and executes commands interactively, so the result is immediate.
5 / 19
-
Quick check
A one-off experiment at the prompt now works. What makes the same work repeatable tomorrow?
AKeeping the terminal history of that session and reading it back
History records what was typed; it is not a program that can be run again.
BSaving the code in a script file
Right. When the interpreter is invoked with a file name, it reads and executes a script from that file, so saved code can be run and edited again.
CInstalling a community package that does something similar
A package may help later, but it does not preserve the code that already works.
7 / 19
-
Keep your progress in the app
That’s 3 of 7 quick checks. In the app they stay answered, and every lesson remembers where you left off.
-
Quick check
A developer must build the same objects from a saved file every time, then examine them by hand. Which invocation does both?
ARun the script with `-i` before its file name
Right. Passing `-i` before a script runs the script and then enters interactive mode, so repeatable setup is followed by manual inspection.
BEdit the file without running it
An unrun file builds nothing, so there is nothing to inspect.
CRun an unrelated module with `-m` and leave the setup script unused
The `-m` form runs a module's source as a script; choosing an unrelated one abandons the setup that was required.
10 / 19
-
Quick check
A module in the project is also useful as a program on its own. Which form runs its source as a script?
A`python -i` with no file, then retype the module's code
The `-i` option enters interactive mode; on its own it does not locate and run a module's source.
B`python -m module`
Right. `python -m module` executes the source file for that module as if its full name had been given on the command line.
CPassing the module's name to a shell command that is not Python
The module is Python source, so the Python interpreter is what has to run it.
13 / 19
-
Quick check
A utility has outgrown one file, and two other programs need the same parsing behavior without copied code. What is the appropriate next step?
APaste the parsing code into both programs
Three copies of the same behavior have to be corrected three times, which is what splitting a program into modules avoids.
BLeave the behavior in an unsaved interactive session
An unsaved session cannot be reused by another program at all.
CMove the parsing behavior into a module the other programs can reuse
Right. Python allows a program to be split into modules that can be reused by other Python programs.
16 / 19
-
Quick check
A team has identified a file-processing task, validated one operation at the prompt, and now needs repeatable execution plus reuse in a second program. Which sequence fits?
ASave a script, extract a module, then use suitable library facilities
Right. The path runs from interactive feedback to a saved script, then to modules for reuse, and then to the facilities the language and the distributed library already provide.
BRepeat every command by hand each time
Manual repetition is exactly what saving a script removes, and it leaves nothing to reuse.
CConvert the operation into a platform-specific shell command and duplicate it in both programs
A platform-specific command gives up portability, and duplicating it recreates the copied code a module is meant to prevent.
19 / 19
-
7 quick checks · then the test
In the app, finishing the quick checks opens this lesson’s 10-question test, and the ones you miss come back exactly when you’re about to forget them.
The whole course, on your phone
Lessons you can read, audio you can listen to on the way to work, and practice that remembers what you got wrong.