In Python, numbers are a data type used to represent numeric values. There are mainly two types of numbers: integers (int) and floating-point numbers (float).
1. Integers (int):
Integers are whole numbers without any decimal point.
```python
x = 5
y = -10
```
2. Floating-point numbers (float):
Floating-point numbers have decimal points or use scientific notation.
```python
a = 3.14
b = 2.0
```
You can perform various operations with numbers, such as addition, subtraction, multiplication, and division:
```python
# Addition
result_addition = x + a
# Subtraction
result_subtraction = y - b
# Multiplication
result_multiplication = x * b
# Division
result_division = a / y
```
Python also supports complex numbers, which are written in the form `a + bj`, where `a` and `b` are real numbers, and `j` represents the imaginary unit.
```python
z = 2 + 3j
```
These basic examples illustrate the use of numbers in Python.
0 Comments