Sept. 6, 2021


Teacher Resources
...

Originally posted: Sept. 6, 2021
Last edited: 1 year, 2 months ago


Python Numeric Types

There are three numeric types in Python:

  • int
  • float
  • complex

Python Integers

 

In Python, integers are zero, positive or negative whole numbers without a fractional part and having unlimited precision, e.g. 0, 100, -10.

Leading zeros in non-zero integers are not allowed e.g. 000123 is invalid number, 0000 is 0.

Python does not allow comma as number delimiter. Use underscore _ as a delimiter instead.

Integers can be binary, octal, and hexadecimal values.

>>> 0b11011000 # binary

216

>>> 0o12 # octal

10

>>> 0x12 # hexadecimal

15

 

Python Variables

Python has no command for declaring a variable.

A variable is created the moment you first assign a value to it.