menu

Python Control Structures


1. 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)


2. Which of the following statements is used to remove an element from a list in Python?

list.remove(element)

list.pop(index)

list.delete(element)

list.splice(index, 1)


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

for loop

while loop

do-while loop

switch loop


4. Which of the following is not a comparison operator in Python?

<=

:=


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

[ ]

( )

{ }

| |


6. Which of the following statements is used to convert a string to uppercase in Python?

string.upper()

string.toUpper()

string.casefold()

string.capitalize()


7. Which of the following statements is used to iterate over a range of numbers in Python?

for i in range(n):

for i in range(0, n):

for i in range(1, n+1):

All of the above


8. 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():


9. Which statement is used to exit a loop prematurely in Python?

break

continue

pass

exit


10. Which operator is used to check if two values are not equal in Python?

=

==

===

!=