What the Python Automation for IT exam covers
- Python Scripting Foundations for Automation158 questions
- Files, Data Formats, and Text Processing168 questions
- OS, Process, and Task Automation163 questions
- APIs, Web, and Cloud Automation164 questions
- Network Automation, Testing, and CI/CD158 questions
Free Python Automation for IT practice test questions
A sample of 10 questions with answers and explanations. Sign up free to practice all 811.
-
What does the following script print? nums = [1, 2, 3, 4] print([n * n for n in nums if n % 2 == 0])
- A[4, 16]Correct
- B[1, 4, 9, 16]
- C[2, 4]
- D[1, 9]
✓ Correct answer: AThe comprehension keeps only even values (2 and 4) because of the if filter, then squares each survivor, giving 4 and 16.
Why the other options are wrong- BThat squares every element and ignores the if filter that keeps only even numbers.
- CThat keeps the even numbers but forgets to square them in the expression part.
- DThat squares the odd numbers, which is the opposite of the n % 2 == 0 filter.
-
Select TWO ways to make a Python CLI script exit with a nonzero status a shell can detect.
- ACall sys.exit(1)Correct
- BRaise SystemExit(2)Correct
- CCall sys.exit(0)
- DReturn 1 from a helper function
✓ Correct answer: A, Bsys.exit(n) and raising SystemExit(n) both terminate the interpreter with that status; any nonzero value signals failure to the calling shell.
Why the other options are wrong- CExit code 0 signals success, not failure.
- DReturning a value from a function does not set the process exit status.
-
What does the following script print? from pathlib import Path print(Path('logs/app.log').parent)
- AlogsCorrect
- Bapp.log
- Clogs/app.log
- D.
✓ Correct answer: APath.parent returns the path without its final component, so the parent of logs/app.log is logs.
Why the other options are wrong- Bapp.log is the final component (p.name), which parent strips off rather than returns.
- Cparent removes the last component, so it does not return the full original path.
- DA single dot is the parent only for a bare file name with no directory part.
-
What does this script print? from pathlib import Path p = Path("report.txt") print(p.with_suffix(".csv"))
- Areport.csvCorrect
- Breport.txt.csv
- Creport
- D.csv
✓ Correct answer: Awith_suffix replaces the existing extension with the new one, turning report.txt into report.csv.
Why the other options are wrong- Bwith_suffix swaps the extension rather than appending a second one.
- CThe stem is kept and given the new extension, so it is not stripped to report.
- DThe file stem report is preserved in front of the new extension.
-
Which call creates a nested directory and does not raise if the path already exists?
- APath('out/logs').mkdir(parents=True, exist_ok=True)Correct
- BPath('out/logs').mkdir(parents=True)
- CPath('out/logs').mkdir()
- Dos.mkdir('out/logs')
✓ Correct answer: Aparents=True creates any missing intermediate directories, and exist_ok=True suppresses the error when the target already exists, making the call idempotent.
Why the other options are wrong- BWithout exist_ok=True it raises FileExistsError when the directory already exists.
- CThis has neither flag, so it fails on a missing parent and on an existing target.
- Dos.mkdir creates only a single level and raises if the parent is missing or the path exists.
-
What does this script print? import os os.environ["STAGE"] = "prod" print(os.environ.get("STAGE"))
- AprodCorrect
- BNone
- CSTAGE
- DKeyError
✓ Correct answer: AAssigning to os.environ sets the variable for this process, so the following get returns the value just stored, 'prod'.
Why the other options are wrong- BNone appears only when the key is absent, but it was just assigned.
- Cget returns the value, not the key name.
- DThe key exists after assignment, so no lookup error occurs.
-
You need to POST a JSON body and have the Content-Type set to application/json automatically. Which call is correct?
- Arequests.post(url, json=payload)Correct
- Brequests.post(url, data=payload)
- Crequests.post(url, body=payload)
- Drequests.post(url, params=payload)
✓ Correct answer: AThe json argument encodes the object as JSON and adds the application/json Content-Type header automatically.
Why the other options are wrong- Bdata= sends form-encoded content and does not set a JSON content type.
- Cbody is not a valid requests parameter.
- Dparams adds URL query string values, not a request body.
-
True or False: A requests.Session reuses the underlying TCP connection and persists headers across multiple calls to the same host.
- ATrueCorrect
- BFalse
✓ Correct answer: AA Session keeps a connection pool so repeat calls reuse sockets, and any headers or auth set on it apply to every request it sends.
Why the other options are wrong- BIt is not False; connection reuse and persistent headers are the main reasons to use a Session.
-
Which decorator runs one test function against several input and expected-value pairs?
- A@pytest.mark.parametrizeCorrect
- B@pytest.fixture
- C@pytest.mark.skip
- D@pytest.loop
✓ Correct answer: A@pytest.mark.parametrize names the arguments and supplies a sequence of value tuples, and pytest runs the decorated test once per tuple as its own separately reported case. This replaces copy-pasting near-identical tests and makes clear exactly which input failed.
Why the other options are wrong- B@pytest.fixture supplies a single reusable dependency to a test; it does not iterate a test over multiple input sets.
- C@pytest.mark.skip unconditionally skips the test, so it runs zero times rather than repeating across inputs.
- DThere is no @pytest.loop decorator in pytest; the API for running one test over data is parametrize.
-
Which mock method verifies that a patched function was called exactly one time?
- Amock.assert_called_once()Correct
- Bmock.was_called(1)
- Cmock.verify_once()
- Dmock.assert_ran()
✓ Correct answer: Aunittest.mock provides assert_called_once, which raises AssertionError unless the mock was called exactly one time.
Why the other options are wrong- BThere is no was_called method on Mock objects.
- CThere is no verify_once method on Mock objects.
- DThere is no assert_ran method on Mock objects.
Who this Python Automation for IT practice exam is for
This practice set is for anyone preparing for the Python Automation for IT exam - from first-time candidates building a foundation to experienced Python practitioners doing a final review before test day. If you learn best by working through realistic questions and reading why each answer is right or wrong, it is built for you.
How to use this Python Automation for IT practice exam
- Start with the free sample questions above to gauge your current baseline.
- Read the full explanation on every question, including why each wrong option is wrong.
- Track your weak domains and focus your study where you are losing the most marks.
- Once you are scoring consistently well, take a timed, full-length mock exam.
- Use your readiness score to decide when you are ready to book the real Python Automation for IT exam.
Related Python resources
- Python Automation for IT study guideKey concepts
- Python practice examsAll Python
- Certification pathWhere this fits
- Certification exam guides & tipsBlog
- Plans & pricingFree & paid
- Hands-on python-automation labsLearn
- Python automation cheat sheetCheat sheet
- How these questions are written and reviewedMethodology
- Report a problem with a questionCorrections
- PCAP practice examRelated
- PCEP practice examRelated
Python Automation for IT practice exam FAQ
How many questions are in the Python Automation for IT practice exam on CertGrid?
CertGrid has 811 practice questions for Python Automation for IT, covering 5 exam domains. This is a vendor-neutral CertGrid practical track, not an official vendor exam.
What is the passing score for Python Automation for IT?
This is a vendor-neutral CertGrid practical track, not an official certification exam. CertGrid scores your practice against a 70% readiness threshold on a 50-question mock, so you know when you are ready for real Python automation work.. You have about 90 min to complete it. CertGrid tracks your readiness against the exam objectives so you know where to focus.
Are these official Python Automation for IT exam questions?
No. CertGrid is an independent practice platform. We do not provide real or leaked exam questions. Our questions are original and designed to help you practice the concepts, scenarios, and difficulty style of the Python Automation for IT exam.
Is there a free Python Automation for IT practice test?
Yes. You can take a free Python Automation for IT practice test straight away: a fixed set of 20 practice questions for this exam, retryable as often as you like, with no credit card required. You get readiness scoring and a weak-domain breakdown on those questions. Paid plans unlock the full 811-question bank, timed mock exams and full-bank domain analytics.
What CertGrid is (and is not)
CertGrid is an independent IT certification practice platform for Azure, AWS, Google, Cisco, Security, Linux, Kubernetes, Terraform, and other certification tracks. It provides objective-mapped practice questions, readiness scoring, weak-domain drills, and explanations to help learners understand what to study next.
Independent & original. CertGrid is not affiliated with or endorsed by Microsoft, AWS, Google, Cisco, CompTIA, the Linux Foundation, HashiCorp, or other certification vendors. Questions are original practice items designed to mirror certification concepts and exam style. CertGrid does not provide official exam questions or braindumps.