Python Fundamentals · Practice set 5 of 8
Interpreter and Program Basics: 10 practice questions
10 free Python Fundamentals practice questions on Interpreter and Program Basics, with an explanation for every answer. Untimed. The full mock exam and the timed version are in the app.
-
Question 1 of 10
What does the interpreter do when it is invoked with a Python file name?
- AIt stores the file name as an empty string.
- BIt treats every file line as a shell command.
- CIt enters interactive mode without reading the file.
- DIt reads and executes a script from that file.
Show the answer
A file-name argument selects script execution; terminal input without a file is the neighboring interactive mode.
Next → 1 / 10 -
Question 2 of 10
How does Python expose a script name and its subsequent arguments to a program?
- AAs strings in the list `sys.path`.
- BAs strings in the list `sys.argv`.
- CAs variables created in the program's global scope.
- DAs numbers in the tuple `sys.argv`.
Show the answer
Importing `sys` exposes `sys.argv`, whose string elements describe the invocation rather than the module search path.
Next → 2 / 10 -
Question 3 of 10
Which encoding does Python use for a source file when the file has no encoding declaration?
- AWindows-1252
- BASCII
- CUTF-16
- DUTF-8
Show the answer
UTF-8 is the source-file default; another supported codec requires an explicit declaration.
Next → 3 / 10 -
Question 4 of 10
Which invocation locates a module and executes its source as a script?
- A`python -c module [arg] ...`
- B`python -m module [arg] ...`
- C`python module -m [arg] ...`
- D`python -i module [arg] ...`
Show the answer
The `-m` option selects a module by name; `-c` selects statements supplied directly and `-i` requests interaction after a script.
Next → 4 / 10 -
Question 5 of 10
A command is run with `python -c command alpha beta`. What happens to `alpha` and `beta`?
- AThey remain in `sys.argv` for the command to handle.
- BThey are converted to numbers before the command runs.
- CThey replace `sys.argv[0]` with an empty string.
- DThey are consumed as additional interpreter options.
Show the answer
Values after the `-c` command are program arguments, while `sys.argv[0]` identifies the `-c` invocation.
Next → 5 / 10 -
Keep the ones you got wrong
In the app, every question you miss comes back exactly when you’re about to forget it.
-
Question 6 of 10
What prompt normally indicates that the interactive interpreter expects a continuation line?
- A`%%%`
- B`...`
- C`---`
- D`>>>`
Show the answer
The secondary prompt uses three dots for continuation; three greater-than signs form the primary prompt for a new command.
Next → 6 / 10 -
Question 7 of 10
Where should a non-default source encoding declaration appear when a Unix shebang is the first line?
- AOn the second line, immediately after the shebang.
- BInside the first string literal in the file.
- COn the final line, after all Python statements.
- DOn the first line, replacing the shebang.
Show the answer
The shebang is the documented exception to the first-line rule, so the encoding declaration moves to line two.
Next → 7 / 10 -
Question 8 of 10
A developer must execute `inspect.py` from disk and then immediately explore the resulting state at a prompt. Which invocation feature satisfies both constraints?
- APlace `-m` after the script name.
- BPlace `-i` before the script name.
- CPlace `-c` before the script name.
- DPass `-` as the script name.
Show the answer
The `-i` option preserves script execution and adds interactive mode afterward; the other forms select direct commands, modules, or standard input.
Next → 8 / 10 -
Question 9 of 10
A package module is started with `python -m tools.report weekly --quiet`. The module must identify its invocation form and receive both trailing values. Which `sys.argv` description is correct?
- AElement zero is empty, and only `weekly` remains available to the module.
- BElement zero is the module's file text, and both trailing values become numbers.
- CElement zero is `-m`, and both trailing values are consumed as interpreter options.
- DElement zero is the located module's full name, and both trailing values remain available.
Show the answer
Module execution records the located module's full name at index zero and leaves later arguments for that module.
Next → 9 / 10 -
Question 10 of 10
At the base interpreter prompt, pressing Left arrow prints a visible escape sequence. The session must continue, and the developer needs to correct the current line. What conclusion follows from the documented behavior?
- AInteractive mode is unavailable, so the interpreter must be restarted with `-i`.
- BThe source encoding is wrong, so a UTF-8 declaration must be added at the prompt.
- CContinuation mode is active, so a blank line will enable the arrow keys.
- DCommand-line editing is unavailable, so only Backspace can remove current-line characters.
Show the answer
A printed escape sequence diagnoses missing line-editing support, but it does not end interactive execution; Backspace remains available for the current line.
Next → 10 / 10 -
You’ve finished this set
That’s 10 questions on Interpreter and Program Basics. In the app 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.