menu

Python Control Structures


1. Which of the following statements is used to add an element to the end of a list in Python?

list.add(element)

list.insert(index, element)

list.append(element)

list.push(element)


2. Which statement is used to create a set in Python?

[ ]

( )

{ }

| |


3. Which of the following statements is used to check if a number is odd in Python?

num % 2 == 0

num % 2 == 1

num.is_odd()

num.odd()


4. Which of the following statements is used to check if a key is in a dictionary in Python?

key in dictionary

dictionary.contains(key)

dictionary.include(key)

key.exists(dictionary)


5. Which statement is used to create a list in Python?

[ ]

( )

{ }

| |


6. Which of the following is not a type of loop in Python?

for loop

while loop

do-while loop

nested loop


7. Which loop executes a block of code a fixed number of times?

for loop

while loop

do-while loop

switch loop


8. Which loop executes a block of code as long as a specified condition is true?

for loop

while loop

do-while loop

switch loop


9. Which of the following statements is used to loop through a dictionary in Python?

for key in dictionary:

for value in dictionary:

for item in dictionary:

for key, value in dictionary.items():


10. Which of the following statements is used to import a module in Python?

module.import(module_name)

import module_name

from module_name import *

All of the above