menu

Python Control Structures


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

string.upper()

string.toUpper()

string.casefold()

string.capitalize()


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

[ ]

( )

{ }

| |


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


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


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


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

<=

:=


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

and

or

not

nor


9. Which of the following statements is used to concatenate two strings in Python?

string1.add(string2)

string1.concat(string2)

string1 + string2

string1.join(string2)


10. 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()