Numbers & Arithmetic
Python works with two main number types:
- Integers (
int) β whole numbers like5,-12, or0; - Floats (
float) β numbers with decimals like3.14or-2.5.
Python determines the type based on how the number is written.
Arithmetic Operations in Python
Python includes all standard math operations with clear syntax:
Addition
+ adds values. Mixing int and float produces a float.
Subtraction
- subtracts the right-hand value from the left. Works with positives and negatives.
Multiplication
* multiplies values. If a float is involved, the result is a float.
Division
/ divides and always returns a float, even if the result is whole (e.g., 8 / 2).
Floor Division
// divides and rounds down to the nearest whole number. Result type depends on operands.
Modulo
% gives the remainder of a division. Works with positive, negative, and floats.
Exponentiation
** raises a number to a power. Also works with fractional exponents for roots.
Operator precedence (PEMDAS)
Python follows standard rules to decide which operation comes first:
- Parentheses;
- Exponentiation;
- Multiplication / Division / Floor Division / Modulo;
- Addition / Subtraction.
Integers vs floats in operations
When performing arithmetic:
- Division always returns a
float; - Mixing
intandfloatpromotes the result tofloat; - Use
//to get a rounded-down integer result.
Summary
- Python includes support for
intandfloattypes; - Arithmetic operators:
+,-,*,/,//,%,**; /returns floats,//gives floor-divided integers;- Operator precedence follows PEMDAS.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 5
Numbers & Arithmetic
Swipe to show menu
Python works with two main number types:
- Integers (
int) β whole numbers like5,-12, or0; - Floats (
float) β numbers with decimals like3.14or-2.5.
Python determines the type based on how the number is written.
Arithmetic Operations in Python
Python includes all standard math operations with clear syntax:
Addition
+ adds values. Mixing int and float produces a float.
Subtraction
- subtracts the right-hand value from the left. Works with positives and negatives.
Multiplication
* multiplies values. If a float is involved, the result is a float.
Division
/ divides and always returns a float, even if the result is whole (e.g., 8 / 2).
Floor Division
// divides and rounds down to the nearest whole number. Result type depends on operands.
Modulo
% gives the remainder of a division. Works with positive, negative, and floats.
Exponentiation
** raises a number to a power. Also works with fractional exponents for roots.
Operator precedence (PEMDAS)
Python follows standard rules to decide which operation comes first:
- Parentheses;
- Exponentiation;
- Multiplication / Division / Floor Division / Modulo;
- Addition / Subtraction.
Integers vs floats in operations
When performing arithmetic:
- Division always returns a
float; - Mixing
intandfloatpromotes the result tofloat; - Use
//to get a rounded-down integer result.
Summary
- Python includes support for
intandfloattypes; - Arithmetic operators:
+,-,*,/,//,%,**; /returns floats,//gives floor-divided integers;- Operator precedence follows PEMDAS.
Thanks for your feedback!