What is the primary purpose of the elif statement in Python?
- To handle exceptions
- To create a loop
- To check multiple conditions in sequence
- To end the program
Which of the following best describes the purpose of iteration in programming?
- To execute a block of code only if a condition is true
- To execute instructions in a specific order
- To repeat a set of instructions a certain number of times or until a condition is met
- To create reusable code
What is the result of the expression print("5 + 3") in Python?
What is the difference between = and == in Python?
- Both are used for assignment
- = is a comparison operator, and == is used for assignment
- = is used for assignment, and == is a comparison operator
- There is no difference; they are interchangeable
Which of the following statements is an example of a selection structure?
for i in range(5):if x > 0:while True:print("Hello, World!")
What is a list in Python?
- A mathematical operation
- A collection of related data
- A reserved keyword
- A data type
What is meant by a local variable?
- A variable defined outside any function
- A variable with a global scope
- A variable that can be accessed from any part of the program
- A variable defined within a function
In Python, how can you convert a string variable num_str to an integer?
int(num_str)convertToInt(num_str)toInteger(num_str)num_str.toInt()
In Python, which keyword is used to exit a loop prematurely?
What does the len() function in Python do when applied to a string?
- Returns the number of words in the string
- Returns the length of the string
- Converts the string to lowercase
- Checks if the string contains a specific substring