Python Basics MCQ Questions with Answers (Latest 2026)

Practice Python Basics MCQ questions with detailed explanations and clear answer validation. These MCQs help you revise core concepts, compare close options, and improve accuracy for interviews, certification exams, and technical screening rounds. Use this updated 2026 set to strengthen fundamentals and confidence.

Related mcq: Python Advanced Coding MCQ | Python Asyncio MCQ | Python Concurrency MCQ | RAG Basics MCQ | LLM Engineer Basics MCQ

Q1. Which keyword is used to define a function in Python?

Select an answer to check.

Answer: def

Here, def is the right choice. `def` creates a named function block. It aligns directly with what the question asks about which keyword is used to define a function. A quick elimination of partially true options helps confirm it.

Q2. Which data type stores key-value pairs?

Select an answer to check.

Answer: dictionary

In this case, dictionary is correct. Dictionary maps keys to values. It aligns directly with what the question asks about which data type stores key-value pairs. A quick elimination of partially true options helps confirm it.

Q3. What is the result type of `len('hello')`?

Select an answer to check.

Answer: int

The best option here is int. `len()` returns count as integer. It aligns directly with what the question asks about what is the result type of `len('hello')`. A quick elimination of partially true options helps confirm it.

Q4. Which loop is best for iterating items in a list?

Select an answer to check.

Answer: for

For this question, for is correct. `for` directly iterates over list elements. It aligns directly with what the question asks about which loop is best for iterating items in. A quick elimination of partially true options helps confirm it.

Q5. Which statement exits a loop immediately?

Select an answer to check.

Answer: break

break is the correct answer here. `break` stops current loop execution. It aligns directly with what the question asks about which statement exits a loop immediately. A quick elimination of partially true options helps confirm it.

Q6. Which symbol starts a single-line comment in Python?

Select an answer to check.

Answer: #

Here, # is the right choice. Python uses # for single-line comments. This matches the core idea being tested around which symbol starts a single-line comment in python. A quick elimination of partially true options helps confirm it.

Q7. Which values are boolean literals in Python?

Select an answer to check.

Answer: True/False

In this case, True/False is correct. Boolean literals are capitalized: True and False. This matches the core idea being tested around which values are boolean literals in python. A quick elimination of partially true options helps confirm it.

Q8. Which of these is immutable?

Select an answer to check.

Answer: tuple

The best option here is tuple. Tuple items cannot be changed after creation. This matches the core idea being tested around which of these is immutable. A quick elimination of partially true options helps confirm it.

Q9. Which function converts a string to an integer?

Select an answer to check.

Answer: int()

For this question, int() is correct. Int() converts valid numeric strings to integers. This matches the core idea being tested around which function converts a string to an integer. A quick elimination of partially true options helps confirm it.

Q10. Which method adds one item to the end of a list?

Select an answer to check.

Answer: append()

append() is the correct answer here. Append() inserts a single item at the end. This matches the core idea being tested around which method adds one item to the end. A quick elimination of partially true options helps confirm it.

Q11. How do you access a dictionary value by key `name` in `d`?

Select an answer to check.

Answer: d['name']

Here, d['name'] is the right choice. Square-bracket key access retrieves dictionary values. That is exactly the concept behind how do you access a dictionary value by in this context. A quick elimination of partially true options helps confirm it.

Q12. In slicing `text[1:4]`, which index is excluded?

Select an answer to check.

Answer: 4

In this case, 4 is correct. Python slicing includes start and excludes end index. That is exactly the concept behind in slicing `text[1:4]`, which index is excluded in this context. A quick elimination of partially true options helps confirm it.

Q13. What does `range(5)` generate?

Select an answer to check.

Answer: 0 to 4

The best option here is 0 to 4. Range(5) starts from 0 and stops before 5. That is exactly the concept behind what does `range(5)` generate in this context. A quick elimination of partially true options helps confirm it.

Q14. Which loop repeats while a condition is true?

Select an answer to check.

Answer: while

For this question, while is correct. While runs until its condition becomes false. That is exactly the concept behind which loop repeats while a condition is true in this context. A quick elimination of partially true options helps confirm it.

Q15. Which statement skips the current loop iteration?

Select an answer to check.

Answer: continue

continue is the correct answer here. Continue moves to the next loop iteration. That is exactly the concept behind which statement skips the current loop iteration in this context. A quick elimination of partially true options helps confirm it.

Q16. What does `None` represent in Python?

Select an answer to check.

Answer: No value

Here, No value is the right choice. None is used to represent absence of value. It fits the requirement in the prompt about what does `none` represent in python. A quick elimination of partially true options helps confirm it.

Q17. Which operator checks value equality?

Select an answer to check.

Answer: ==

In this case, == is correct. == compares values, while = assigns. It fits the requirement in the prompt about which operator checks value equality. A quick elimination of partially true options helps confirm it.

Q18. Which operator performs floor division?

Select an answer to check.

Answer: //

The best option here is //. // returns quotient without decimal part. It fits the requirement in the prompt about which operator performs floor division. A quick elimination of partially true options helps confirm it.

Q19. Which operator gives remainder?

Select an answer to check.

Answer: %

For this question, % is correct. % returns remainder after division. It fits the requirement in the prompt about which operator gives remainder. A quick elimination of partially true options helps confirm it.

Q20. Which operator means power in Python?

Select an answer to check.

Answer: **

** is the correct answer here. ** is exponentiation operator. It fits the requirement in the prompt about which operator means power in python. A quick elimination of partially true options helps confirm it.

Q21. When does `and` return True?

Select an answer to check.

Answer: Both operands true

Here, Both operands true is the right choice. Logical and requires both sides to be true. This is the most accurate statement for when does `and` return true. A quick elimination of partially true options helps confirm it.

Q22. When does `or` return True?

Select an answer to check.

Answer: Any operand true

In this case, Any operand true is correct. Logical or is true if at least one side is true. This is the most accurate statement for when does `or` return true. A quick elimination of partially true options helps confirm it.

Q23. What does `not` do?

Select an answer to check.

Answer: Negates boolean

The best option here is Negates boolean. Not reverses truth value. This is the most accurate statement for what does `not` do. A quick elimination of partially true options helps confirm it.

Q24. What type does `input()` return?

Select an answer to check.

Answer: str

For this question, str is correct. Input() returns user input as string. This is the most accurate statement for what type does `input()` return. A quick elimination of partially true options helps confirm it.

Q25. Which function converts to float?

Select an answer to check.

Answer: float()

float() is the correct answer here. Float() converts valid values to floating point. This is the most accurate statement for which function converts to float. A quick elimination of partially true options helps confirm it.

Q26. How do you start an f-string?

Select an answer to check.

Answer: f'...'

Here, f'...' is the right choice. Prefix f enables expression interpolation in strings. It aligns directly with what the question asks about how do you start an f-string. The other options are either incomplete or contextually incorrect.

Q27. Which string method makes text lowercase?

Select an answer to check.

Answer: lower()

In this case, lower() is correct. Lower() returns lowercase copy of the string. It aligns directly with what the question asks about which string method makes text lowercase. The other options are either incomplete or contextually incorrect.

Q28. Which method splits a string into a list?

Select an answer to check.

Answer: split()

The best option here is split(). Split() divides string by separator into list. It aligns directly with what the question asks about which method splits a string into a list. The other options are either incomplete or contextually incorrect.

Q29. Which method joins list items into a string?

Select an answer to check.

Answer: join()

For this question, join() is correct. Separator.join(list) combines elements into one string. It aligns directly with what the question asks about which method joins list items into a string. The other options are either incomplete or contextually incorrect.

Q30. Which syntax is a list comprehension?

Select an answer to check.

Answer: [x for x in nums]

[x for x in nums] is the correct answer here. Square brackets denote list comprehension. It aligns directly with what the question asks about which syntax is a list comprehension. The other options are either incomplete or contextually incorrect.

Q31. Which dictionary method returns all keys?

Select an answer to check.

Answer: keys()

Here, keys() is the right choice. Keys() returns a view of dictionary keys. This matches the core idea being tested around which dictionary method returns all keys. The other options are either incomplete or contextually incorrect.

Q32. Which dictionary method returns all values?

Select an answer to check.

Answer: values()

In this case, values() is correct. Values() returns a view of dictionary values. This matches the core idea being tested around which dictionary method returns all values. The other options are either incomplete or contextually incorrect.

Q33. What is tuple packing?

Select an answer to check.

Answer: a,b=1,2

The best option here is a,b=1,2. Multiple values can be packed into a tuple implicitly. This matches the core idea being tested around what is tuple packing. The other options are either incomplete or contextually incorrect.

Q34. Which statement correctly unpacks two values?

Select an answer to check.

Answer: a,b=(1,2)

For this question, a,b=(1,2) is correct. Tuple unpacking assigns each value to each variable. This matches the core idea being tested around which statement correctly unpacks two values. The other options are either incomplete or contextually incorrect.

Q35. What is a default function parameter?

Select an answer to check.

Answer: Predefined fallback value

Predefined fallback value is the correct answer here. Defaults are used when caller omits that argument. This matches the core idea being tested around what is a default function parameter. The other options are either incomplete or contextually incorrect.

Q36. What does `return` do in a function?

Select an answer to check.

Answer: Exit and send result

Here, Exit and send result is the right choice. Return ends function execution and returns value. That is exactly the concept behind what does `return` do in a function in this context. The other options are either incomplete or contextually incorrect.

Q37. What does `*args` collect?

Select an answer to check.

Answer: Positional args

In this case, Positional args is correct. *args collects variable positional arguments as tuple. That is exactly the concept behind what does `*args` collect in this context. The other options are either incomplete or contextually incorrect.

Q38. What does `**kwargs` collect?

Select an answer to check.

Answer: Keyword args

The best option here is Keyword args. **kwargs collects variable keyword arguments as dict. That is exactly the concept behind what does `**kwargs` collect in this context. The other options are either incomplete or contextually incorrect.

Q39. What is a lambda in Python?

Select an answer to check.

Answer: Anonymous function

For this question, Anonymous function is correct. Lambda creates small unnamed functions. That is exactly the concept behind what is a lambda in python in this context. The other options are either incomplete or contextually incorrect.

Q40. Which keyword modifies a global variable inside function?

Select an answer to check.

Answer: global

global is the correct answer here. Global tells Python to use module-level variable. That is exactly the concept behind which keyword modifies a global variable inside function in this context. The other options are either incomplete or contextually incorrect.

Q41. What is `pass` used for?

Select an answer to check.

Answer: Placeholder statement

Here, Placeholder statement is the right choice. Pass does nothing and is used where statement is required. It fits the requirement in the prompt about what is `pass` used for. The other options are either incomplete or contextually incorrect.

Q42. What does `is` compare?

Select an answer to check.

Answer: Identity

In this case, Identity is correct. Is checks whether two references point to same object. It fits the requirement in the prompt about what does `is` compare. The other options are either incomplete or contextually incorrect.

Q43. What does `in` check?

Select an answer to check.

Answer: Membership

The best option here is Membership. In checks whether value exists in container. It fits the requirement in the prompt about what does `in` check. The other options are either incomplete or contextually incorrect.

Q44. Which file mode opens for reading?

Select an answer to check.

Answer: r

For this question, r is correct. R is read mode. It fits the requirement in the prompt about which file mode opens for reading. The other options are either incomplete or contextually incorrect.

Q45. Which file mode overwrites existing file?

Select an answer to check.

Answer: w

w is the correct answer here. W truncates file before writing. It fits the requirement in the prompt about which file mode overwrites existing file. The other options are either incomplete or contextually incorrect.

Q46. Which file mode appends data?

Select an answer to check.

Answer: a

Here, a is the right choice. A writes at end without truncating existing content. This is the most accurate statement for which file mode appends data. The other options are either incomplete or contextually incorrect.

Q47. Why use `with open(...)`?

Select an answer to check.

Answer: Auto-close file

In this case, Auto-close file is correct. With ensures file is closed even if error occurs. This is the most accurate statement for why use `with open(...)`. The other options are either incomplete or contextually incorrect.

Q48. Which exception occurs for missing file in read mode?

Select an answer to check.

Answer: FileNotFoundError

The best option here is FileNotFoundError. Python raises FileNotFoundError when file path is invalid. This is the most accurate statement for which exception occurs for missing file in read. The other options are either incomplete or contextually incorrect.

Q49. What is purpose of try/except?

Select an answer to check.

Answer: Handle runtime errors

For this question, Handle runtime errors is correct. Try/except catches exceptions to avoid crash. This is the most accurate statement for what is purpose of try/except. The other options are either incomplete or contextually incorrect.

Q50. Which block always executes after try/except?

Select an answer to check.

Answer: finally

finally is the correct answer here. Finally runs regardless of exception state. This is the most accurate statement for which block always executes after try/except. The other options are either incomplete or contextually incorrect.