menu

Python Control Structures


1. Which of the following statements is used to call a function in Python?

call function_name(arguments)

function_name.call(arguments)

function_name(arguments)

arguments(function_name)


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

block

segment

suite

module


3. Which statement is used to skip the current iteration of a loop in Python?

break

continue

pass

skip


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


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


6. Which of the following statements is used to define a default value for a function argument in Python?

def function_name(argument=value):

def function_name(argument, value):

def function_name(argument=default(value)):

def function_name(argument, default=value):


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

[ ]

( )

{ }

| |


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

string.upper()

string.toUpper()

string.casefold()

string.capitalize()


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


10. Which statement is used to handle exceptions in Python?

try-except

try-catch

try-throw

try-finally