Booleans + Comparisons

Booleans are another type of operation. The term is not particularly definitive of its function however, booleans are operations that represent values for true or false. They are used for comparing values and seeing if the comparison is true or false. This term is most easily explained through examples;

[Console]

>>>boolean = True

=====

[Interpreter]

True

 

[Console]

>>> 1 == 2

>>> “Hello” == “Hello”

=====

[Interpreter]

False

True

Another important type of boolean is the comparison function. The comparison function can be defined as the “not equal” operator and the is symbolised by “!=”. When using the comparison function, if a code comes out to be true then in the interpreter the value will come out false. Essentially, the comparison functions causes the opposite of the answer to be in the code.

[Console]

>>> 1 != 1

>>> “two” != “three”

>>> 3 != 4

=====

[Interpreter]

False

True

True

When using this comparison function, the use of greater than (>) and less than (<) are commonly used.  In addition greater than and equal to (>=)  and less than and equal to (>=) are also be used. As expected they can be used in conjunction with booleans or comparisons to cause a true or false answer to be made.

[Console]

>>> 1 < 2

>>> 3 < 3

>>> 4 <= 5

>>> 6 >= 6

=====

[Interpreter]

True

False

True

True

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s