Numerical Data Types

## Description

While not necessary for day-to-day Sage use, Python has 4 numerical data types that may become necessary to know when programming in the language, inside or outside of Sage. These types are int, long, float and complex. Types int and long are both integers, with the sole difference being that the absolute value of an int cannot be above 9223372036854775807. float is a decimal number with up to 12 digits of precision. For numbers with 12 integer digits and above, a float value will become scientific notation, and eventually around 308 digits and above will be estimated as inf, or infinity. complex is a complex number in the form a + bj. Note that python uses j for $\sqrt{-1}$ instead of i. Sage has its own types that it automatically assigns to new values, so to specifically use the Python types, you must use their constructors, which are simply commands named the same as the type name which convert the value passed to them to the python type. In order to demonstrate the type of the values we are constructing, we will use the type command, which returns the type of the value or object it is passed.

## Sage Cell

#### Code

a = int(1)
print a, type(a)

a = long(100)
print a, type(a)

a = float(2.5)
print a, type(a)

a = complex(2 + 4j)
print a, type(a)


none

## Tags

Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

## Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.

## Attribute

Author:

Date: 27 Mar 2019 00:18

Submitted by: Zane Corbiere