Skip to content

Files

28 lines (20 loc) · 1.1 KB

File metadata and controls

28 lines (20 loc) · 1.1 KB

Python Numbers

There are 3 distinct numeric types in python.

Integers have unlimited precision; thus, they can be as large as you need them to be.

Example: myInt = 789456123

Floats are limited to the precision of a C double value. You can check your systems float precision by using the following commands:

import sys
sys.float_info

Example: myFloat = 123.4567

Complex numbers are broken into two parts, a real and imaginary part. Both are floating point numbers and can be accessed using the .real and .imag properties. You can create a complex number using the complex(real, imag) command. In Python, the imaginary constant usually dictated with an i is replaced with a j.

Example: myComplex = complex(2, 3.4) # myComplex = (2+3.4j)

Instructions:

  • Assign an integer value to the myInteger variable
  • Assign a float value to the myFloat variable
  • Assign a complex value to the myComplex variable. Make sure it has both a real and imaginary part.