Question 510
A system Python installation should remain untouched while a project tests a new dependency version. Which step creates isolation?
- sys.executable
- python -m pip freeze
- python -m pip install -r requirements.txt
- python3 -m venv .venv
Explanation
Correct Answer
D:venv creates a dedicated environment with interpreter paths and site-packages for a project. Activation changes which python and pip commands are resolved.
Incorrect Answers
A:Python's sys.executable identifies the path of the executing interpreter; the evidence calls for isolating Python project dependencies, not merely this separate operation.
B:pip freeze lists installed distributions in requirement-style syntax; the task involves isolating Python project dependencies, whereas this addresses another subsystem.
C:pip reads dependency specifications from the file and installs compatible distributions into the chosen interpreter environment; its scope differs from isolating Python project dependencies, so it cannot meet the stated requirement.
Question 511
A maintenance program needs to run a command with separate arguments without using a shell command string. Which Python API fits?
- FileNotFoundError
- pathlib.Path
- subprocess.run(['systemctl','status','sshd'], check=True)
- json.loads(response_text)
Explanation
Correct Answer
C:subprocess.run executes a program with explicit argument boundaries. Avoiding shell=True reduces shell-injection risk when inputs vary.
Incorrect Answers
A:FileNotFoundError identifies a missing path during file operations; it answers a neighboring question rather than invoking external commands without shell interpolation.
B:Path objects provide path joining and filesystem operations while handling platform path conventions; that changes a different part of the system; the requested outcome is invoking external commands without shell interpolation.
D:json.loads parses JSON text into dictionaries, lists and scalar values; it will not provide invoking external commands without shell interpolation under these conditions.
Question 512
A Python administrator wants formatting and static checks integrated into CI to catch issues before deployment. Which practice is appropriate?
- import netutil
- lower_case_with_underscores
- Automated linting and style validation
- if __name__ == '__main__':
- pip
Explanation
Correct Answer
C:Linters and formatters can flag style inconsistencies and common errors before runtime. Passing lint does not establish full program correctness.
Incorrect Answers
A:Python imports modules and exposes their named functions and values through the module namespace; the requirement is checking Python style and likely defects in CI, outside the effect of this choice.
B:PEP 8 generally favors snake_case for variables and functions; it does not deliver checking Python style and likely defects in CI, which is decisive in this scenario.
D:The module's __name__ value identifies direct execution versus normal import; the task involves checking Python style and likely defects in CI, whereas this addresses another subsystem.
E:pip resolves and installs Python distributions from configured indexes; its scope differs from checking Python style and likely defects in CI, so it cannot meet the stated requirement.
Question 513
A fixed set of configuration constants should be stored in an ordered immutable sequence. Which built-in type is suitable?
- if 'port' in config:
- list
- dict
- tuple
Explanation
Correct Answer
D:A tuple is an ordered collection whose element references cannot be reassigned after creation. Its contents can nevertheless include mutable objects such as lists.
Incorrect Answers
A:The in operator tests membership in dictionary keys; that is not equivalent to representing an immutable ordered configuration sequence.
B:Python lists preserve element order and allow append, deletion and assignment; the administrator instead needs representing an immutable ordered configuration sequence; this option serves a different purpose.
C:Dictionaries associate unique hashable keys with values and support efficient lookup; it answers a neighboring question rather than representing an immutable ordered configuration sequence.
Question 514
A Python program must show its exact interpreter location because two environments are installed. Which expression can inspect it?
- source .venv/bin/activate
- sys.executable
- python3 -m venv .venv
- python -m pip freeze
Explanation
Correct Answer
B:Python's sys.executable identifies the path of the executing interpreter. This helps verify virtual-environment selection.
Incorrect Answers
A:The activate script adjusts the invoking shell's PATH and environment for the virtual environment; it will not provide identifying the running Python interpreter under these conditions.
C:venv creates a dedicated environment with interpreter paths and site-packages for a project; the requirement is identifying the running Python interpreter, outside the effect of this choice.
D:pip freeze lists installed distributions in requirement-style syntax; it does not deliver identifying the running Python interpreter, which is decisive in this scenario.
Question 515
A script must construct cross-platform filesystem paths without manual string concatenation. Which library abstraction is suitable?
- with open(path, encoding='utf-8') as f:
- pathlib.Path
- subprocess.run(['systemctl','status','sshd'], check=True)
- FileNotFoundError
Explanation
Correct Answer
B:Path objects provide path joining and filesystem operations while handling platform path conventions. They do not bypass permissions.
Incorrect Answers
A:The with statement uses a context manager to close an opened file reliably; the task involves building filesystem paths using path objects, whereas this addresses another subsystem.
C:subprocess.run executes a program with explicit argument boundaries; that is not equivalent to building filesystem paths using path objects.
D:FileNotFoundError identifies a missing path during file operations; the administrator instead needs building filesystem paths using path objects; this option serves a different purpose.
Question 516
A feature has passed review and should be integrated into the checked-out main branch with a merge commit when needed. Which operation fits?
- git merge feature
- git switch -c experiment
- Squash merge
- Annotated tag
Explanation
Correct Answer
A:git merge integrates the named branch into the current branch history. Conflicts must be resolved before the merge completes.
Incorrect Answers
B:git switch -c creates the named branch at the current commit and checks it out; this does not achieve integrating a feature branch without rebasing on the system described.
C:A squash merge combines changes into a single staged result for one new commit; it will not provide integrating a feature branch without rebasing under these conditions.
D:An annotated tag references a revision and can include a message and author metadata; using it would leave integrating a feature branch without rebasing unresolved.
Question 517
A reviewer wants to inspect the history of commits affecting a repository. Which command produces an overview?
- git pull
- git config --local user.email admin@example.org
- git log --oneline
- git clone repository-url
Explanation
Correct Answer
C:git log displays revisions, and --oneline formats abbreviated commit identifiers with subjects. It does not change branch history.
Incorrect Answers
A:git pull obtains remote changes and integrates them according to configuration or explicit options; it does not deliver reviewing commit history concisely, which is decisive in this scenario.
B:Local Git configuration is stored in the repository and overrides broader user settings; the evidence calls for reviewing commit history concisely, not merely this separate operation.
D:git clone creates a local repository from a remote source with fetched history and default branch; its scope differs from reviewing commit history concisely, so it cannot meet the stated requirement.
Question 518
A team member needs a full local copy of an existing remote repository and its history. Which command fits?
- git clone repository-url
- git pull
- git config --local user.email admin@example.org
- git push origin feature
- git log --oneline
Explanation
Correct Answer
A:git clone creates a local repository from a remote source with fetched history and default branch. It also configures a remote reference.
Incorrect Answers
B:git pull obtains remote changes and integrates them according to configuration or explicit options; it answers a neighboring question rather than obtaining an existing Git repository.
C:Local Git configuration is stored in the repository and overrides broader user settings; that changes a different part of the system; the requested outcome is obtaining an existing Git repository.
D:git push updates a remote branch when authorization and remote history allow it; this does not achieve obtaining an existing Git repository on the system described.
E:git log displays revisions, and --oneline formats abbreviated commit identifiers with subjects; it will not provide obtaining an existing Git repository under these conditions.
Question 519
One file was staged accidentally but its working-tree edits must remain intact. Which command unstages it?
- git stash push
- git reset --mixed HEAD~1
- git restore --staged config.yml
- git diff
Explanation
Correct Answer
C:Restore with --staged resets the index entry to the current commit while preserving working-tree edits. It differs from discarding edits entirely.
Incorrect Answers
A:Stash saves eligible working-tree and index changes in a local stack for later application; using it would leave removing staged status without losing edits unresolved.
B:A mixed reset moves the current branch and resets the index while retaining tracked working-tree changes; the requirement is removing staged status without losing edits, outside the effect of this choice.
D:A plain git diff compares unstaged working-tree edits with the index; it does not discard staged content. --cached instead inspects staged differences against the commit; the evidence calls for removing staged status without losing edits, not merely this separate operation.
Question 520
Multiple small feature commits should appear as one combined change during integration. Which Git technique supports this?
- Annotated tag
- git rebase main
- git config --local user.email admin@example.org
- git switch -c experiment
- Squash merge
- git merge feature
Explanation
Correct Answer
E:A squash merge combines changes into a single staged result for one new commit. It does not preserve every feature commit as a separate ancestor on the target branch.
Incorrect Answers
A:An annotated tag references a revision and can include a message and author metadata; its scope differs from collapsing a feature series into one integrated commit, so it cannot meet the stated requirement.
B:Rebase reapplies commits onto another base and rewrites their identities; that is not equivalent to collapsing a feature series into one integrated commit.
C:Local Git configuration is stored in the repository and overrides broader user settings; the administrator instead needs collapsing a feature series into one integrated commit; this option serves a different purpose.
D:git switch -c creates the named branch at the current commit and checks it out; it answers a neighboring question rather than collapsing a feature series into one integrated commit.
F:git merge integrates the named branch into the current branch history; this does not achieve collapsing a feature series into one integrated commit on the system described.