menu

Python Control Structures


1. Which of the following statements is used to check if a number is a multiple of another number in Python?

num % multiple == 0

num / multiple == 0

num % multiple == 1

num / multiple == 1


2. Which statement is used to call a function in Python?

call

invoke

run

None of the above


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


4. Which of the following statements is used to find the length of a string in Python?

string.length()

len(string)

length(string)

size(string)


5. Which statement is used to return a value from a function in Python?

return

exit

break

pass


6. Which keyword is used to define a block of code in Python?

block

segment

suite

module


7. Which of the following is not a logical operator in Python?

and

or

not

nor


8. Which statement is used to create a tuple in Python?

[ ]

( )

{ }

| |


9. Which of the following statements is used to sort a list in ascending order in Python?

list.sort()

sorted(list)

list.sort(reverse=True)

sorted(list, reverse=True)


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

string.upper()

string.toUpper()

string.casefold()

string.capitalize()