Python Test Questions and Answers: 20 MCQs + 5 Coding Questions

These Python test questions and answers are built for testers and freshers preparing for online assessments and data or ETL testing interviews in India. Try each question before opening the answer. The first half covers Python basics; the second half covers what data testing roles actually use: pandas and pytest.

Tip: save this page as a PDF from your browser (Ctrl+P → Save as PDF) for offline revision.

How to Use This Test

  • Give yourself 20 minutes for the 20 MCQs.
  • Write the 5 coding answers yourself before reading ours.
  • Score yourself at the end and revise the topics you missed.

Python Basics (Q1–Q10)

Q1. What is the output of print(type([]))?

  • A. <class 'tuple'>
  • B. <class 'list'>
  • C. <class 'dict'>
  • D. <class 'set'>
Show answer
Answer: B. [] is an empty list.

Q2. Which of these is immutable?

  • A. list
  • B. dict
  • C. tuple
  • D. set
Show answer
Answer: C. Tuples cannot be changed after creation.

Q3. What does len("ETL") return?

  • A. 2
  • B. 3
  • C. 4
  • D. Error
Show answer
Answer: B. The string has three characters.

Q4. What is 7 // 2?

  • A. 3.5
  • B. 3
  • C. 4
  • D. 1
Show answer
Answer: B. // is floor division.

Q5. What does "a,b,c".split(",") return?

  • A. 'abc'
  • B. ['a', 'b', 'c']
  • C. ('a', 'b', 'c')
  • D. ['a,b,c']
Show answer
Answer: B. split returns a list of parts.

Q6. Which keyword handles an exception?

  • A. catch
  • B. except
  • C. error
  • D. handle
Show answer
Answer: B. Python uses try / except.

Q7. What is the output of bool("")?

  • A. True
  • B. False
  • C. None
  • D. Error
Show answer
Answer: B. Empty strings are falsy.

Q8. Which creates a dictionary?

  • A. {1, 2}
  • B. [1: "a"]
  • C. {"id": 1}
  • D. ("id", 1)
Show answer
Answer: C. Key-value pairs inside braces make a dict.

Q9. What does set([1, 1, 2]) give?

  • A. {1, 1, 2}
  • B. {1, 2}
  • C. [1, 2]
  • D. Error
Show answer
Answer: B. Sets keep unique values only, which is handy for duplicate checks.

Q10. What is [x * 2 for x in range(3)]?

  • A. [0, 2, 4]
  • B. [2, 4, 6]
  • C. [0, 1, 2]
  • D. [1, 2, 3]
Show answer
Answer: A. range(3) is 0, 1, 2.

pandas and pytest Questions for Testers (Q11–Q20)

Q11. Which pandas function reads a CSV file?

  • A. pd.open_csv()
  • B. pd.read_csv()
  • C. pd.load_csv()
  • D. pd.csv()
Show answer
Answer: B. read_csv returns a DataFrame.

Q12. What does df.isna().sum() show?

  • A. Total rows
  • B. Missing values per column
  • C. Duplicate rows
  • D. Column types
Show answer
Answer: B. A standard null check in ETL testing.

Q13. Which finds duplicate order_id rows?

  • A. df.unique("order_id")
  • B. df.duplicated("order_id")
  • C. df.drop("order_id")
  • D. df.count("order_id")
Show answer
Answer: B. duplicated marks repeated keys.

Q14. Which merge finds rows missing in target?

  • A. how="inner"
  • B. how="left", indicator=True
  • C. how="cross"
  • D. concat()
Show answer
Answer: B. left_only rows exist in source but not target.

Q15. What does assert a == b do in pytest when false?

  • A. Prints a warning
  • B. Fails the test
  • C. Skips the test
  • D. Nothing
Show answer
Answer: B. A failed assert fails the test with details.

Q16. Where are shared pytest fixtures usually placed?

  • A. main.py
  • B. conftest.py
  • C. setup.cfg
  • D. __init__.py
Show answer
Answer: B. pytest discovers fixtures in conftest.py automatically.

Q17. Which runs the same test for many inputs?

  • A. @pytest.fixture
  • B. @pytest.mark.parametrize
  • C. @pytest.skip
  • D. @staticmethod
Show answer
Answer: B. parametrize generates one test per value.

Q18. Which library is commonly used to connect Python to SQL databases?

  • A. NumPy
  • B. SQLAlchemy
  • C. Matplotlib
  • D. Requests
Show answer
Answer: B. SQLAlchemy works with pandas.read_sql.

Q19. What does df.groupby("region")["amount"].sum() return?

  • A. One total
  • B. Total amount per region
  • C. Count per region
  • D. Average per region
Show answer
Answer: B. Same as SQL GROUP BY with SUM.

Q20. float("nan") == float("nan") is:

  • A. True
  • B. False
  • C. Error
  • D. None
Show answer
Answer: B. NaN never equals itself; use isna() in comparisons.

Python Coding Test Questions (Q21–Q25)

Q21. Write a function that returns duplicate values in a list.

Python
def duplicates(items):
    seen, dups = set(), set()
    for x in items:
        if x in seen:
            dups.add(x)
        seen.add(x)
    return dups

assert duplicates([1, 2, 2, 3, 3]) == {2, 3}

Q22. Count the words in a sentence.

Python
from collections import Counter
print(Counter("data test data".split()))   # Counter({'data': 2, 'test': 1})

Q23. Reverse a string and check if it is a palindrome.

Python
def is_palindrome(s):
    s = s.lower().replace(" ", "")
    return s == s[::-1]

assert is_palindrome("Madam")

Q24. Find IDs present in source but not in target (lists).

Python
source = [101, 102, 103, 104]
target = [101, 103]
missing = sorted(set(source) - set(target))
print(missing)   # [102, 104]

Q25. Read a CSV and report columns with missing values.

Python
import pandas as pd

df = pd.read_csv("customers.csv")
nulls = df.isna().sum()
print(nulls[nulls > 0])

Score Yourself

Score (MCQs)What it meansNext step
17–20Interview-ready on Python basicsMove to ETL automation interview questions
12–16Good base, gaps in pandas or pytestRevise with Python for testers
Below 12Start with fundamentalsFollow the 6-week plan in Python for testers

Tips for Online Python Tests

  • Many Indian companies use online assessment platforms for the first round. The questions above are practice questions in a similar style, not questions from any specific platform.
  • Read the full question before coding; edge cases (empty input, duplicates, NULL/NaN) are where marks are lost.
  • Run small examples with print statements before submitting.
  • Manage time: skip and return instead of getting stuck.

Practise Under Interview Conditions

Reading answers is not the same as answering under time pressure. ETL Testing Interview Questions & Answers – Practice Tests gives you 500+ questions with detailed explanations, from fresher to experienced level, including Python and ETL automation questions alongside SQL, data warehouse and scenario-based rounds. Attempt a test, review every explanation, and retake until you are consistently above 80%.

  • Timed practice tests that feel like a real screening round
  • Python, automation, SQL and scenario questions in one place
  • Detailed answers, so each wrong attempt teaches you something
  • Lifetime access and Udemy’s refund policy

Prepare for your ETL testing interview: top 50 questions · in-depth answers · for experienced (3–5 years) · for 10 years experience · SQL query questions · scenario-based questions · data warehouse questions · questions for freshers · free mock test · database testing questions · Python ETL testing questions · Informatica questions · SQL questions for freshers · DBMS questions · data validation questions · service-company questions · ETL automation testing questions · Big 4 (Deloitte, PwC, EY, KPMG) · tough questions · self introduction · SQL test MCQs

Frequently Asked Questions

What Python questions are asked in a test for freshers?

Data types, lists and dictionaries, loops, string methods, exceptions, simple functions and short coding tasks such as finding duplicates or reversing a string.

Which Python topics matter most for ETL or data testing roles?

pandas (read_csv, merge, groupby, isna, duplicated), pytest (assert, fixtures, parametrize) and connecting to databases with SQLAlchemy.

Can I download these Python test questions as a PDF?

Use your browser’s print option (Ctrl+P, then Save as PDF) to save this page.

Are these the actual questions from company online tests?

No. They are original practice questions in a similar style. Use them to build skill, not to memorise answers.

Asim Noaman Lodhi
Written by

Asim Noaman Lodhi

Certified Google Partner · QA Consultant · 12+ Years IT

QA consultant specializing in ETL testing and data quality. Trained 913+ students to transition into data testing roles through hands-on, real-world instruction.

4.5 Rating 913+ Students Google Partner 79 Lectures

Ready for the Real Interview? Practise 500+ Questions

500+ ETL testing interview questions with detailed answers, from fresher to experienced level.

Practice 500+ Questions