15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

562<br />

Using Operators<br />

Table 3-1<br />

Mathematical Operators<br />

Mathematical Operator Purpose Example<br />

+ Addition 5 + 3.4<br />

- Subtraction 203.9 - 9.12<br />

* Multiplication 39 * 146.7<br />

/ Division 45/ 8.41<br />

% Modula division (returns the remainder) 35 % 9 = 8<br />

** Exponentiation 5**2 = 25<br />

divmod (x,y)<br />

(Python only) Returns both x / y and x % y divmod (12,8) = (1,4)<br />

When Python uses the division operator (/) to divide two integers, the result<br />

will be an integer, such as<br />

9/4 = 2<br />

If at least one number is a decimal, the result will also be a decimal, such as<br />

Or<br />

9.0/4 = 2.25<br />

9/4.0 = 2.25<br />

Relational operators compare two values and return a True or False value.<br />

The six relational operators available are shown in Table 3-2.<br />

Table 3-2<br />

Relational Operator<br />

Purpose<br />

== Equal<br />

!= Not equal<br />

< Less than<br />

Relational Operators<br />

Greater than<br />

>= Greater than or equal to<br />

< = ><br />

(Perl only)<br />

Comparison with signed result

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!