Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to judge whether it is negative in python?
How to judge whether it is negative in python?
In Python, you can use comparison operators.

Quantity = -5

If quantity & lt0:

Print ("This is a negative number")

Otherwise:

Print ("This is not a negative number")

In the above code, we first define a variable num, and its value is -5. Then, we use the if statement to check whether this number is negative, if so, we output the corresponding message, otherwise, we output another message. In this example, because num is less than 0, the output message is "This is a negative number".

In addition to using comparison operators