Python Programming — C20 DCME Fifth Semester (Board Exam Scope): 18 MCQs with answers

All 18 multiple-choice questions from this kit, free and with no sign-up.

Warm-up · 7 questions

Q1. In Python, what is a variable?

Beginner
A A fixed box that stores only integers B A reserved keyword for declaring types C A name that refers to a value in memory D A function that prints values
Show answer & explanation

A name that refers to a value in memory

A Python variable is a name bound to a value in memory. No type declaration is required, and the name can later refer to a value of a different type.

Q2. Which statement about Python's typing is correct?

Beginner
A A name can never refer to a different type later B Every variable must be declared with a type first C Types are decided by the file extension D Types are determined at runtime, not declared in advance
Show answer & explanation

Types are determined at runtime, not declared in advance

Python uses dynamic typing: the type of a value is determined at runtime, so the same name can later refer to a value of a different type.

Q3. A student writes `x = 10` and then `x = "hello"` in the same program. What happens?

Beginner
A It raises a type error immediately B `x` keeps the integer 10 and ignores the string C Python deletes `x` and creates a new variable D It runs fine; `x` now refers to a string
Show answer & explanation

It runs fine; `x` now refers to a string

Because of dynamic typing, reassigning `x` to a string is perfectly legal. The name simply points to a new value.

Q4. Which operator assigns a value rather than comparing two values?

Beginner
A `=` B `!=` C `is` D `==`
Show answer & explanation

`=`

`=` is the assignment operator. `==` compares two values for equality, and `!=` and `is` are also comparison-style operators.

Q5. Which family does the `in` operator belong to?

Beginner
A Membership B Arithmetic C Assignment D Identity
Show answer & explanation

Membership

`in` and `not in` are membership operators; they check whether a value is present in a sequence or collection.

Q6. What sequence does `range(5)` generate?

Beginner
A 0, 1, 2, 3, 4 B 0, 1, 2, 3, 4, 5 C 1, 2, 3, 4, 5 D 5, 4, 3, 2, 1
Show answer & explanation

0, 1, 2, 3, 4

`range(5)` starts at 0 and stops before 5, producing 0, 1, 2, 3, 4.

Q7. Python uses dynamic typing, so variable types are determined at runtime rather than declared in advance.

Beginner
A True B False
Show answer & explanation

True

Python uses dynamic typing, so variable types are determined at runtime rather than declared in advance.

Building up · 6 questions

Q8. Which loop is best when you must repeat a block until a condition becomes false?

Intermediate
A A `try` block B A single `if` statement C A `for` loop over a list D A `while` loop
Show answer & explanation

A `while` loop

A `while` loop repeats as long as its condition stays true, which suits condition-driven repetition. A `for` loop is meant for iterating over a sequence.

Q9. Inside a loop, you want to skip even numbers and keep processing the rest. Which statement fits?

Intermediate
A `assert` B `continue` C `pass` D `break`
Show answer & explanation

`continue`

`continue` skips the rest of the current iteration and moves to the next one, so even numbers are skipped while the loop keeps running.

Q10. What does `*args` collect inside a function?

Intermediate
A Default values for all parameters B The function's return values C Extra positional arguments, as a tuple D Extra keyword arguments, as a dictionary
Show answer & explanation

Extra positional arguments, as a tuple

`*args` gathers extra positional arguments into a tuple. It is `**kwargs` that gathers extra keyword arguments into a dictionary.

Q11. Which pair of collections is ordered and allows duplicates?

Intermediate
A Lists and tuples B Sets and dictionaries C Sets and tuples D Dictionaries and lists
Show answer & explanation

Lists and tuples

Lists and tuples are both ordered and allow duplicate values. Sets are unordered with no duplicates, and dictionary keys must be unique.

Q12. A list `a` exists. Which line creates an independent copy so that changing `b` leaves `a` untouched?

Intermediate
A `b = a[:]` B `b == a` C `b = a` D `b = a is a`
Show answer & explanation

`b = a[:]`

`b = a[:]` (or `b = list(a)`) makes an independent copy. `b = a` only creates a second name for the same list, so changes show up in both.

Q13. Which statement about strings is correct?

Intermediate
A Strings are unordered and store no duplicates B Strings are immutable sequences of characters C Strings are mutable and can be edited in place D Strings can only hold digits
Show answer & explanation

Strings are immutable sequences of characters

A string is an immutable sequence of characters. Methods like `upper()` return new strings rather than changing the original.

Topper level · 5 questions

Q14. Which statement about `break` and `continue` is correct?

Advanced
A Both restart the loop from the beginning B `break` skips one iteration; `continue` exits the loop C Both exit the loop immediately D `break` exits the loop; `continue` skips to the next iteration
Show answer & explanation

`break` exits the loop; `continue` skips to the next iteration

`break` leaves the loop entirely, while `continue` abandons only the current iteration and proceeds to the next one.

Q15. A program must respond gracefully when a user enters text where a number was expected. Which structure should it use?

Advanced
A `try` with `except` and `finally` B An `assert` statement alone C A `for` loop over `range()` D A `while` loop with `break`
Show answer & explanation

`try` with `except` and `finally`

Exception handling with `try`, `except`, and `finally` lets the program catch the runtime error and continue instead of crashing. `assert` only raises an error; it does not handle one.

Q16. Which statement about data hiding in Python is correct?

Advanced
A Only functions can hide data, not classes B A leading underscore signals restricted access by convention C Data hiding requires declaring every attribute as `public` D Python blocks all access to attributes starting with `_`
Show answer & explanation

A leading underscore signals restricted access by convention

Python uses naming conventions: `_name` signals internal use and `__name` triggers name mangling. The restriction is by convention and mangling, not a hard access block.

Q17. You are tasked with writing a function that takes a list of integers and returns a new list containing only the odd integers, while also handling any potential errors gracefully. Which implementation correctly achieves this?

Advanced
A ```python def filter_odds(numbers): odds = [] for n in numbers: if n % 2 == 0: continue odds.append(n) return odds ``` B ```python def filter_odds(numbers): odds = [] for n in numbers: if isinstance(n, int): if n % 2 != 0: odds.append(n) return odds ``` C ```python def filter_odds(numbers): return [n for n in numbers if n % 2 != 0] ``` D ```python def filter_odds(numbers): return [n for n in numbers if n % 2 == 0] ```
Show answer & explanation

```python def filter_odds(numbers): odds = [] for n in numbers: if n % 2 == 0: continue odds.append(n) return odds ```

The correct option uses a `for` loop with a `continue` statement to skip even numbers and append only odd integers to the list. This effectively filters out the even numbers.

Q18. Given the following class definition, what will be the output of the code snippet when executed? ```python class BankAccount: def __init__(self, balance): self.__balance = balance def deposit(self, amount): self.__balance += amount def get_balance(self): return self.__balance account = BankAccount(100) account.deposit(50) print(account.get_balance()) ```

Advanced
A 50 B Error: 'BankAccount' object has no attribute '__balance' C 100 D 150
Show answer & explanation

150

The output is 150 because the `deposit` method successfully adds 50 to the initial balance of 100, demonstrating correct encapsulation and method functionality in the class.

Make your own

Your notes can be a kit like these

Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.

  • Chapter notes
  • Flashcards
  • Practice MCQs
  • Scored tests
  • Exam prep

Get Veda free See what students get

Free to start · No ads · Works in 42 languages