W3Schools Python Programming Fundamentals Quiz

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Thames
T
Thames
Community Contributor
Quizzes Created: 11982 | Total Attempts: 187,298
| Attempts: 17 | Questions: 20 | Updated: Aug 15, 2026
Please wait...
Question 1 / 21
🏆 Rank #-- ▾
0 %
0/100
Score 0/100

1. What is the correct way to create a variable in Python?

Explanation

In Python, create a variable by assigning a value to a name with `=`. For example, `x = 5` stores the value `5` in `x`. Python does not use declarations such as `var` or `variable` for ordinary variable assignment.

Submit
Please wait...
About This Quiz
W3Schools Python Programming Fundamentals Quiz - Quiz

This quiz assesses your understanding of Python programming fundamentals, including variables, data types, control flow, functions, and object-oriented programming concepts. Designed for college-level learners, it evaluates your ability to write and understand Python code, work with built-in methods, and apply core programming principles. Perfect for students preparing for W3Schools Python... see morecertification or strengthening their programming foundation. see less

2.

What first name or nickname would you like us to use?

You may optionally provide this to label your report, leaderboard, or certificate.

2. In Python, ____ is used to import modules or functions.

Explanation

The `import` keyword makes code from another module available in a Python program. For example, `import math` lets you use functions such as `math.sqrt()`. To import a specific function directly, you can write `from math import sqrt`. This supports code reuse and organization.

Submit

3. Which keyword is used to create a function in Python?

Explanation

In Python, `def` is the keyword used to define a function. It is followed by the function’s name, parentheses for any parameters, and a colon. The indented code beneath it forms the function body.

Submit

4. Which loop structure is used to iterate over a sequence in Python?

Explanation

A `for` loop iterates through the items in a sequence, such as a list, string, or tuple, executing its code block once for each item.

Submit

5. In Python, what is the correct syntax for a dictionary?

Explanation

Python dictionaries use curly braces `{}` to enclose key–value pairs, with a colon separating each key from its value. For example, `{key: value}` represents a dictionary containing one pair; multiple pairs are separated by commas. Square brackets create lists, while parentheses group expressions or define tuples.

Submit

6. Which keyword is used to create a conditional statement?

Explanation

The `if` keyword creates a conditional statement by checking whether a specified condition is true. When it is, the program executes the associated block of code; otherwise, it can skip that block or follow an alternative branch.

Submit

7. The append() method adds an element to the ____ of a list.

Explanation

In Python, `append()` places the specified element after all existing elements in a list. It increases the list’s length by one and leaves the order of the existing elements unchanged.

Submit

8. What does the range(5) function generate?

Explanation

In Python, `range(5)` generates integers starting at 0 and stopping before 5. This produces the sequence `0, 1, 2, 3, 4`.

Submit

9. Which method removes the last item from a list?

Explanation

`pop()` removes and returns the last item in a list by default. It can also remove an item at a specified index when one is provided.

Submit

10. What keyword is used to handle exceptions in Python?

Explanation

Python uses the `except` keyword to catch and handle exceptions raised within a `try` block. It lets a program respond to errors and continue running or perform appropriate cleanup instead of stopping unexpectedly.

Submit

11. True or False: Lists in Python are indexed starting from 1.

Explanation

Python lists use zero-based indexing, so the first item is accessed with index `0`, the second with index `1`, and so on. Negative indices can also access items from the end of a list.

Submit

12. What does the split() method do?

Explanation

The `split()` method breaks a string into smaller parts and returns those parts as a list. By default, it separates the string wherever whitespace appears, though you can provide a different separator, such as a comma.

Submit

13. True or False: Python uses indentation to define code blocks.

Explanation

Python uses leading whitespace, usually spaces, to show which statements belong together in structures such as functions, loops, and conditional statements. Statements at the same indentation level are part of the same block, while increased indentation begins a nested block. Incorrect or inconsistent indentation can cause an `IndentationError`, so indentation is part of Python’s syntax.

Submit

14. Which of the following is a mutable data type in Python?

Explanation

A list is mutable, meaning its elements can be added, removed, or changed after the list is created. Tuples, strings, and frozensets are immutable and cannot be modified after creation.

Submit

15. Which method converts a string to uppercase?

Explanation

In Python, `upper()` is a string method that returns a new string with all lowercase letters converted to uppercase. It does not change the original string; the other listed options are not standard Python string methods.

Submit

16. What is the correct way to create a class in Python?

Explanation

Python class definitions use the lowercase keyword `class`, followed by the class name and a colon. The class body is then written on indented lines beneath it. Python does not use `Class` with a capital letter or a semicolon at the end of the declaration.

Submit

17. Which built-in function returns the type of an object?

Explanation

In Python, `type()` returns the type (class) of an object. For example, `type(42)` returns ``, while `type("hello")` returns ``. The other options are not built-in Python functions for checking an object’s type.

Submit

18. What is the output of 10 // 3 in Python?

Explanation

In Python, `//` performs floor division, discarding the fractional part of the quotient. Since `10 / 3` is about `3.33`, `10 // 3` evaluates to `3`.

Submit

19. What does the len() function return for the string 'Python'?

Explanation

The `len()` function returns the number of characters in a string. `'Python'` contains six characters, so `len('Python')` returns `6`.

Submit

20. True or False: In Python, strings are immutable.

Explanation

Python strings are immutable, meaning their characters cannot be changed after the string is created. Operations that appear to modify a string, such as replacing a character or changing its case, instead produce a new string. This helps make strings predictable and safe to reuse.

Submit
×
Saved
Thank you for your feedback!
View My Results
Cancel
  • All
    All (20)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What is the correct way to create a variable in Python?
In Python, ____ is used to import modules or functions.
Which keyword is used to create a function in Python?
Which loop structure is used to iterate over a sequence in Python?
In Python, what is the correct syntax for a dictionary?
Which keyword is used to create a conditional statement?
The append() method adds an element to the ____ of a list.
What does the range(5) function generate?
Which method removes the last item from a list?
What keyword is used to handle exceptions in Python?
True or False: Lists in Python are indexed starting from 1.
What does the split() method do?
True or False: Python uses indentation to define code blocks.
Which of the following is a mutable data type in Python?
Which method converts a string to uppercase?
What is the correct way to create a class in Python?
Which built-in function returns the type of an object?
What is the output of 10 // 3 in Python?
What does the len() function return for the string 'Python'?
True or False: In Python, strings are immutable.
play-Mute sad happy unanswered_answer up-hover down-hover success oval cancel Check box square blue
Alert!