Saturday, November 12, 2011

Logical operators

This is a short section to introduce the logical operators in Python. If you've programmed in C, you'll recognise these immediately.


==    Equals
!=Not equal
<Less than
>Greater than
<=Less than or equal to
>=Greater than or equal to


Here's a few examples of their usage.


Mostly self explanatory. You can store the value of the test in a variable by assigning it with the equals sign. As in:

c = x > y

If you examine the value of c, it will contain the boolean answer "False" because x = 1 and y = 2 and therefore x > y is False.


No comments:

Post a Comment