Nisha Global Logo
Free practice test • English only

Python for AI Practice Test

Practise the Python you need for AI work: core syntax, data handling with NumPy and pandas, JSON, environments, async calls and safe handling of API keys.

15 Questions~15 minbeginnerAI Skills

Your progress

Answer all questions, then submit to see your score and explanations.

Answered: 0/15

Question 1

Which library is the standard choice for fast numerical arrays in Python?

librarieseasy

Question 2

What is a pandas DataFrame?

librarieseasy

Question 3

What does [x * 2 for x in range(3)] produce?

syntaxeasy

Question 4

Which function turns a JSON string into a Python dictionary?

data handlingeasy

Question 5

What is a virtual environment for?

environmenteasy

Question 6

What does len({"a": 1, "b": 2}) return?

syntaxeasy

Question 7

What does scikit-learn's train_test_split do?

machine learningeasy

Question 8

Where should an API key for an LLM service be kept?

securityeasy

Question 9

When are async and await most useful in AI apps?

concurrencymedium

Question 10

name = "Ana". What does f"Hello {name}" give?

syntaxeasy

Question 11

Pydantic is commonly used in AI apps to:

librariesmedium

Question 12

How should code handle an API call that may fail?

error handlingmedium

Question 13

What does df.head() show by default?

data handlingeasy

Question 14

What does a NumPy operation like array * 2 do?

librariesmedium

Question 15

Why use a requirements.txt or pyproject.toml file?

environmentmedium

Please answer all questions before submitting.

Python for AI Practice Test: all 15 questions with answers

Try each question first, then open “Show answer” to check the correct option and explanation.

  1. Q1.Which library is the standard choice for fast numerical arrays in Python?

    • A.NumPy
    • B.Flask
    • C.Requests
    • D.Tkinter
    Show answer

    Correct answer: A. NumPy

    NumPy provides n-dimensional arrays and vectorised maths used across the AI ecosystem.

  2. Q2.What is a pandas DataFrame?

    • A.An image format
    • B.A table-like structure with labelled rows and columns
    • C.A neural network layer
    • D.A web server
    Show answer

    Correct answer: B. A table-like structure with labelled rows and columns

    DataFrames are the everyday tool for loading, cleaning and exploring tabular data.

  3. Q3.What does [x * 2 for x in range(3)] produce?

    • A.[2, 4, 6]
    • B.[0, 2, 4]
    • C.[0, 1, 2]
    • D.[1, 2, 3]
    Show answer

    Correct answer: B. [0, 2, 4]

    range(3) gives 0, 1, 2, and each is doubled.

  4. Q4.Which function turns a JSON string into a Python dictionary?

    • A.json.dumps
    • B.json.loads
    • C.str.split
    • D.dict.keys
    Show answer

    Correct answer: B. json.loads

    json.loads parses a string. json.dumps does the reverse.

  5. Q5.What is a virtual environment for?

    • A.Running Python in the cloud only
    • B.Keeping each project's package versions isolated
    • C.Making code run faster
    • D.Hiding code from other users
    Show answer

    Correct answer: B. Keeping each project's package versions isolated

    venv (or tools like uv and conda) stops one project's dependencies from breaking another's.

  6. Q6.What does len({"a": 1, "b": 2}) return?

    • A.1
    • B.2
    • C.3
    • D.4
    Show answer

    Correct answer: B. 2

    len of a dictionary counts its keys.

  7. Q7.What does scikit-learn's train_test_split do?

    • A.Trains two models
    • B.Splits data into training and test sets
    • C.Splits a string into words
    • D.Tests the internet connection
    Show answer

    Correct answer: B. Splits data into training and test sets

    It randomly divides data so the model can be evaluated on examples it did not train on.

  8. Q8.Where should an API key for an LLM service be kept?

    • A.Hard-coded in the source file
    • B.In an environment variable or secrets manager
    • C.In a public GitHub README
    • D.In the prompt text
    Show answer

    Correct answer: B. In an environment variable or secrets manager

    Keys in code get leaked through version control. Load them from the environment instead.

  9. Q9.When are async and await most useful in AI apps?

    • A.For heavy maths on one CPU core
    • B.For running many I/O-bound calls, such as API requests, concurrently
    • C.For writing comments
    • D.For defining classes
    Show answer

    Correct answer: B. For running many I/O-bound calls, such as API requests, concurrently

    While one request waits on the network, others can proceed.

  10. Q10.name = "Ana". What does f"Hello {name}" give?

    • A.Hello {name}
    • B.Hello Ana
    • C.Hello name
    • D.An error
    Show answer

    Correct answer: B. Hello Ana

    f-strings insert the value of expressions inside braces.

  11. Q11.Pydantic is commonly used in AI apps to:

    • A.Draw charts
    • B.Validate data against typed models, for example structured LLM output
    • C.Train neural networks
    • D.Compress files
    Show answer

    Correct answer: B. Validate data against typed models, for example structured LLM output

    Defining a Pydantic model and validating the LLM's JSON catches missing or wrong fields early.

  12. Q12.How should code handle an API call that may fail?

    • A.Ignore errors
    • B.Wrap it in try/except and retry or report the error
    • C.Restart the computer
    • D.Use print statements only
    Show answer

    Correct answer: B. Wrap it in try/except and retry or report the error

    Network calls fail. Catch the error, retry with backoff where it makes sense, and log what happened.

  13. Q13.What does df.head() show by default?

    • A.The last row
    • B.The first 5 rows
    • C.The column names only
    • D.The whole DataFrame
    Show answer

    Correct answer: B. The first 5 rows

    head() previews the first five rows; head(10) shows ten.

  14. Q14.What does a NumPy operation like array * 2 do?

    • A.Repeats the array twice
    • B.Multiplies every element by 2 in one vectorised step
    • C.Raises an error
    • D.Adds 2 to the length
    Show answer

    Correct answer: B. Multiplies every element by 2 in one vectorised step

    Vectorised operations apply to every element without a Python loop, which is much faster.

  15. Q15.Why use a requirements.txt or pyproject.toml file?

    • A.To store passwords
    • B.To record dependencies so others can install the same versions
    • C.To speed up Python
    • D.To hold training data
    Show answer

    Correct answer: B. To record dependencies so others can install the same versions

    Pinned dependencies make the project reproducible on another machine or server.

Your privacy choices

We use cookies and similar technologies for site functionality and, where consent is given, to support advertising partners such as Google AdSense. You can manage your choice here.