---
title: "Python: Programming Fundamentals & Best Practices"
description: "Test your knowledge of Python fundamentals with this quiz covering data types, functions, loops, conditionals, list comprehensions, classes, exception handling, and Python programming best practices."
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/quizzes/post/python-programming-fundamentals-quiz
---

# Python: Programming Fundamentals & Best Practices

Welcome to the Python Basics Quiz! This quiz tests your understanding of fundamental Python concepts, syntax, and programming best practices. Each question is multiple-choice, and you'll find hints to help you along the way. Good luck!

## Questions

### 1. How do you define a function in Python?

- `func my_function():`
- `def my_function():`
- `function my_func():`
- `define my_func():`

**Hint:** Short for "Define".

### 2. What is the correct way to create a list in Python?

- `my_list = {1, 2, 3}`
- `my_list = [1, 2, 3]`
- `my_list = (1, 2, 3)`
- `my_list = <1, 2, 3>`

**Hint:** Uses square brackets.

### 3. How do you insert a comment in Python code?

- `// This is a comment`
- `# This is a comment`
- `-- This is a comment`
- `/* This is a comment */`

**Hint:** The hash character.

### 4. Which data type is used to store Key-Value pairs?

- List
- Dictionary
- Collection
- Sequence

**Hint:** Think of a "Dictionary".

### 5. What is the result of 10 // 3 in Python?

- `3.33`
- `3`
- `1`
- `0`

**Hint:** This is "Floor Division".

### 6. How do you start a "for" loop in Python?

- `for (i=0; i<10; i++)`
- `for x in range(10):`
- `foreach x in list:`
- `for x through range(10):`

**Hint:** for item in collection:

### 7. What does the "len()" function do?

- Calculates the sum of all values
- Returns the total count of items
- Finds the largest value in a list
- Determines the data type of an object

**Hint:** Short for "Length".

### 8. How do you check if "a" is equal to "b"?

- `a = b`
- `a == b`
- `a === b`
- `a.equals(b)`

**Hint:** Comparison requires two symbols.

### 9. What is "PEP 8"?

- A tool for installing packages
- A style guide for Python code
- The latest version of the core
- A library for scientific data

**Hint:** It is about how code looks.

### 10. Which keyword is used to handle exceptions?

- `catch`
- `try...except`
- `on_error...resume`
- `try...handle`

**Hint:** Try to run code, then catch the error.

### 11. What is the "self" parameter in a class method?

- It hides the method from users
- It represents the class instance
- It creates a new class duplicate
- It is a keyword used to end a class

**Hint:** It refers to the specific object being used.

### 12. How do you convert a string "10" to an integer?

- `str.to_int("10")`
- `int("10")`
- `convert.int("10")`
- `(int)"10"`

**Hint:** int()

### 13. What does "immutable" mean?

- The object is globally accessible
- The object state cannot be changed
- The object is deleted after usage
- The object can hold multiple types

**Hint:** Once it is made, it cannot be changed.

### 14. Which method adds an item to the end of a list?

- `add()`
- `append()`
- `push()`
- `insert()`

**Hint:** Think "Attach".

### 15. What is a "Lambda" function?

- A function used for async tasks
- An anonymous, one-line function
- A tool for managing memory leaks
- A method for importing packages

**Hint:** A tiny, one-line function.

### 16. How do you check the data type of a variable "x"?

- `x.get_type()`
- `type(x)`
- `typeof(x)`
- `check_type(x)`

**Hint:** type()

### 17. Which keyword brings in code from another module?

- `include`
- `import`
- `require`
- `using`

**Hint:** Bring it "in".

### 18. What is the correct syntax for a "while" loop?

- `while (x < 5):`
- `while x < 5:`
- `while x < 5 do:`
- `while x < 5 { }`

**Hint:** while condition:

### 19. What is the purpose of "range(5)"?

- It finds a random number
- It generates 0 through 4
- It creates 5 empty lists
- It counts all characters

**Hint:** It generates a sequence.

### 20. What is a "docstring"?

- A file ending in .doc
- A string for documentation
- A string that is frozen
- A string used in prints

**Hint:** Documentation inside a string.

### 21. How do you remove the last item from a list?

- `list.remove()`
- `list.pop()`
- `list.delete()`
- `list.clear()`

**Hint:** Think of "popping" a bubble.

### 22. What is "List Comprehension"?

- A way to summarize a list
- A concise creation syntax
- A method for list sorting
- A tool for list validation

**Hint:** Creating a list in a single line.

### 23. Which operator is used for exponentiation?

- `^`
- `**`
- `pow`
- `exp`

**Hint:** Double multiplication.

### 24. What is the "None" object in Python?

- The integer value of 0
- A value representing null
- The boolean value False
- An empty string value ""

**Hint:** Represents nothing.

### 25. What does the "is" keyword check?

- If values are identical
- If object memory matches
- If the variable exists
- If types are identical

**Hint:** It checks identity, not equality.

### 26. What is the output of "bool(0)"?

- True
- False
- Error
- None

**Hint:** Numbers have truthiness.

### 27. How do you open a file for reading?

- `file.open("data", "r")`
- `open("data", "r")`
- `read("data", "r")`
- `load("data", "r")`

**Hint:** open(filename, mode)

### 28. What is a "Set" in Python?

- A frozen, immutable list
- Unordered unique items
- A list of map keys
- A sorted array of data

**Hint:** Unordered and unique.

### 29. Which keyword returns a function value?

- `send`
- `return`
- `yield`
- `print`

**Hint:** Return.

### 30. What is the "if __name__ == '__main__'" block?

- Identifies script author
- Ensures direct execution
- Sets the application name
- Validates user permissions

**Hint:** It controls execution when a file is imported.
