Python

Numbers

Numbers in Python are used to represent numeric values such as integers and floating-point numbers.

Integers

Integers are whole numbers that can be positive, negative, or zero. For example, the integers 5, -3, and 0 are all valid in Python. You can define an integer in Python by simply assigning it a value, like this:

x = 5
y = -3
z = 0
Floats

Floating-point numbers, also known as floats, are numbers with decimal points. For example, the numbers 3.14, -2.5, and 0.0 are all valid floats in Python. You can define a float in Python by assigning it a value with a decimal point, like this:

a = 3.14
b = -2.5
c = 0.0
Arithmetic Operations

You can perform arithmetic operations on numbers in Python using the standard arithmetic operators: +, -, *, /, %, and **. For example:

x = 5
y = 3

# Addition
print(x + y) # Output: 8

# Subtraction
print(x - y) # Output: 2

# Multiplication
print(x * y) # Output: 15

# Division
print(x / y) # Output: 1.6666666666666667

# Modulus (remainder)
print(x % y) # Output: 2

# Exponentiation
print(x ** y) # Output: 125
Built-in Functions

You can also use the built-in Python functions abs(), max(), and min() to get the absolute value, maximum, and minimum of a number or a list of numbers, respectively. For example:

x = -5
y = 3

# Absolute value
print(abs(x)) # Output: 5

# Maximum value
print(max(x, y)) # Output: 3

# Minimum value
print(min(x, y)) # Output: -5

There are lots of different reasons why we would use numbers in Python, and even more reasons for things like Scientific Computing. However, Python also comes with a standard built-in library called Math, which we will cover later on.