1.6 Number Basics

Numeric data types
Python supports two basic number formats, integer and floating-point. An integer represents a whole number, and a floating-point format represents a decimal number. The format a language uses to represent data is called a data type. In addition to integer and floating-point types, programming languages typically have a string type for representing text.

Basic arithmetic
Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication,
and division.
Four basic arithmetic operators exist in Python:

  1. Addition (+)
  2. Subtraction (-)
  3. Multiplication (*)
  4. Division (/)

Operator precedence
When a calculation has multiple operators, each operator is evaluated in order of precedence. Ex: 1 + 2 * 3 is 7 because multiplication takes precedence over addition. However, (1 + 2) * 3 is 9 because parentheses take precedence over multiplication.

OperatorDescriptionExampleResult
()Parentheses(1 + 2) * 39
**Exponentiation2 ** 416
+,Positive, negative-math.pi-3.14159
*, /Multiplication, division2 * 36
+, –Addition, subtraction1 + 23

Leave a Reply