Python Control Structures
Python Control Structures - Important Points
11. | Which of the following is not a valid conditional statement in Python? |
---|
A. if
B. else
C. switch
D. elif
View Answer Discuss Work SpaceAnswer: option c
Explanation:
Python does not have a built-in switch statement. However, you can simulate a switch statement using if-elif-else statements.
12. | Which statement is used to define a function in Python? |
---|
A. def
B. function
C. define
D. func
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The def statement is used to define a function in Python.
13. | Which statement is used to call a function in Python? |
---|
A. call
B. invoke
C. run
D. None of the above
View Answer Discuss Work SpaceAnswer: option d
Explanation:
In Python, you call a function by using its name followed by parentheses.
14. | Which statement is used to return a value from a function in Python? |
---|
A. return
B. exit
C. break
D. pass
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The return statement is used to return a value from a function in Python.
15. | Which statement is used to handle exceptions in Python? |
---|
A. try-except
B. try-catch
C. try-throw
D. try-finally
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The try-except statement is used to handle exceptions in Python.