What is the purpose of an if-statement in Python?
A. To create loops
B. To define functions
C. To handle exceptions
D. To make decisions
Answer: Option D
Solution (By Examveda Team)
In Python, the purpose of an if-statement is to make decisions.The if-statement allows you to execute certain code blocks based on specified conditions. It evaluates a given expression and, if the result is true, executes the block of code associated with that condition. If the result is false, it may optionally execute an alternative block of code specified by an else statement. The ability to make decisions based on conditions is fundamental to programming, and the if-statement provides a powerful mechanism for controlling the flow of execution in a Python program based on varying circumstances.
Join The Discussion