120k views
5 votes
Give any example of 'if' statement in python. 1 marks

User Goppinath
by
7.5k points

1 Answer

6 votes

Final answer:

An 'if' statement in Python is used to execute a block of code if a specified condition is true. The provided example checks if a person is eligible to vote based on their age.

Step-by-step explanation:

An example of an 'if' statement in Python could be as follows:

age = 18
if age >= 18:
print("You are eligible to vote.")

This 'if' statement checks if the variable age is greater than or equal to 18. If the condition is true, it will print the message "You are eligible to vote." Otherwise, the program will skip the print operation and continue executing the subsequent code.

User Brandon Bloom
by
7.4k points