# Operadores Aritméticos

## <mark style="color:blue;">1. Operadores aritméticos en Python</mark>

A continuación se presentan los operadores aritméticos soportados por Python 3

| Operador      | Ejemplo  | Significado                                                     |
| ------------- | -------- | --------------------------------------------------------------- |
| `+` (unario)  | `+a`     | **Unario Positivo**                                             |
| `+` (binario) | `a + b`  | **Suma**                                                        |
| `-` (unario)  | `-a`     | **Unario Negativo**                                             |
| `-` (binario) | `a - b`  | **Resta**                                                       |
| `*`           | `a * b`  | **Multiplicación**                                              |
| `/`           | `a / b`  | **División**                                                    |
| `%`           | `a % b`  | **Módulo**                                                      |
| `//`          | `a // b` | **División de enteros** (también denominado **Floor Division**) |
| `**`          | `a ** b` | **Exponencial**                                                 |

## <mark style="color:blue;">2. Operadores Unarios</mark>

Los operadores unarios se caracterizan porque se aplican sobre un único operando. En Python se soportan el operador **Unario Positivo** y **Unario Negativo**. Este tipo de operadores se aplican sobre tipos numéricos en Python.

```python
num = 10

# Operador unario positivo
+num
10

# Operador unario negativo
-num
-10

# No se pueden restar strings
texto = "Hola mundo"
-texto
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[5], line 2
      1 texto = "Hola mundo"
----> 2 -texto

TypeError: bad operand type for unary -: 'str'
```

## <mark style="color:blue;">3. Suma y Resta</mark>

Los operadores **Suma** y **Resta** son operadores binarios que pueden aplicarse sobre distintos tipos de datos.

### **3.1. Tipos de datos Numéricos**

```python
# Ejemplo con números enteros
num1 = 10
num2 = 5

num1 + num2
15

num1 - num2
5

num3 = num2 - num1
num3
-5

# Ejemplo con números de punto variable
num3 = 1.5
num4 = 0.5
num3 + num4
2.0

num5 = num3 - num4
num5
1.0
```

### **3.2. Strings**

```python
texto1 = "Hola"
texto2 = "mundo"

texto1 + texto2
'Holamundo'

# Espacio entre strings
texto3 = texto1 + ' ' + texto2
texto3
'Hola mundo'

texto1 - texto2 # No se pueden restar strings
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[24], line 1
----> 1 texto1 - texto2

TypeError: unsupported operand type(s) for -: 'str' and 'str'
```

## <mark style="color:blue;">4. Multiplicación y División</mark>

Los operadores **Multiplicación** y **División** son operadores binarios que pueden aplicarse sobre distintos tipos de datos.

### **4.1. Tipos de datos numéricos**

```python
num1 = 10
num2 = 5

num1 * num2
50

num1 / num2 # El resultado de la división siempre es un float
2.0

int(num1 / num2)
2
```

### **4.2. Strings**

```python
text1 = "Hola"
text2 = "mundo"

text1 * text2 # No se pueden multiplicar strings entre sí
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[30], line 1
----> 1 text1 * text2

TypeError: can't multiply sequence by non-int of type 'str'

text1 * 3 # Solo se pueden multiplicar strings por un número entero
'HolaHolaHola'

text1 * 3.5 # No se pueden multiplicar strings por un float
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[32], line 1
----> 1 text1 * 3.5

TypeError: can't multiply sequence by non-int of type 'float'

text1 / text2 # No se pueden dividir strings
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[33], line 1
----> 1 text1 / text2

TypeError: unsupported operand type(s) for /: 'str' and 'str'
```

## 5. Módulo

El operador **Módulo** es un operador binario que devuelve el resto de una división entre tipos de datos numéricos.

```python
num1 = 10
num2 = 7

num1 / num2
1.4285714285714286

num1 % num2 # resto de la división de 10 / 7
3

num3 = 10.5
num4 = 7.2
num3 % num4
3.3
```

## 6. Exponencial

El operador **Exponencial** es un operador binario que se aplica sobre tipos de datos numéricos.

```python
num1 = 10

num1 ** 2
100

num1 ** 5
100000

text1 = "Hola" # No se pueden exponenciar strings
text1 ** 2
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[42], line 2
      1 text1 = "Hola"
----> 2 text1 ** 2

TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
```

## 7. Floor Division

El operador **Floor Division** es un operador binario que se aplica sobre tipos de datos numéricos y devuelve la parte entera del resultado.

```python
num1 = 10
num2 = 7

num1 / num2
1.4285714285714286

num1 // num2 # No hace redondeo, solamente se queda con el número entero
1

num3 = 13
num4 = 7

num3 / num4
1.8571428571428572

num3 // num4
1
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://afsh4ck.gitbook.io/desarrollo-con-python/operadores-en-python/operadores/operadores-aritmeticos.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
