Skip to content

Latest commit

 

History

History
45 lines (33 loc) · 992 Bytes

04-numbers.rst

File metadata and controls

45 lines (33 loc) · 992 Bytes

Numbers in Python

Get your computer to the Python shell (see :doc:`02-setupEnvironment` if you need help)

In Computers we have different types of Numbers, we have whole numbers (Integers), like 5, decimal numbers like $53.26 and Floating point numbers like 3.1415926.....

Integers (whole numbers):

>>> 5
>>> 10
>>> 9999

Floating point numbers (numbers with decimals):

>>> 1.0
>>> .00000567
>>> 3.14159
We can do math on numbers with "Arithmetic Operators":
  • addition: +
  • subtraction: -
  • multiplication: *
  • division: /

Try doing some math in the interactive shell:

>>> 2 + 2
>>> 10 - 5
>>> 400 * 12
>>> 10 / 3
You can Compare numbers using "comparison operators":
  • == Equal to
  • != Not equal to
  • < Less than
  • > Greater than
  • <= Less than or equal to
  • >= Greater than or equal to
>>> 5 == 5
>>> 5 >= 6
>>> 16 * 2 == 32

Decimal numbers are handled in the :mod:`python:decimal` module in python, and are not directly covered in this introduction.