12.07.2015 Views

2. Built-in Data Types

2. Built-in Data Types

2. Built-in Data Types

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

• Even <strong>in</strong> ord<strong>in</strong>ary arithmetic, <strong>in</strong>teger division of<strong>in</strong>tegers differs from decimal division• Example: 11 ÷ 3 gives quotient 3 with rema<strong>in</strong>der 2 for<strong>in</strong>teger division, or 3.666666666666666… (“forever”)for decimal (“long”) division• In Python, if we want an <strong>in</strong>teger result we muststart with two <strong>in</strong>tegers: 11/3 gives 3• For the rema<strong>in</strong>der, use the symbol % (weird!)11%3 gives 2• If at least one of the numbers is a decimal (typefloat), you get a decimal answer11.0/3 and 11/3.0 both give (note the<strong>in</strong>accuracy of the answer) 3.666666666666666529

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

Saved successfully!

Ooh no, something went wrong!