if statement
:# Using the if statement
x = 5
if x > 0:
print("x is positive")
elif x < 0:
print("x is negative")
else:
print("x is zero")
x is positive
if
` statement to check the value of the variable `x
`. If `x
` is greater than `0
`, the program will execute the code in the first `if
` block, which prints the message "x is positive
". x
` is less than `0
`, the program will execute the code in the `elif
` block, which prints the message "x is negative
". If `x
` is neither greater nor less than `0
`, the program will execute the code in the `else
` block, which prints the message "x is zero
".if
` statement to check any condition and execute code based on whether the condition is true or false. You can also use logical operators such as `and`, `or`, and `not` to combine multiple conditions.