# Operators

Operators are one or more characters that can be used to perform operations on data. For example the `+` character is used to perform the addition operation between two numbers. 

## Arithmetic Operators

Arithmetic operators are used to perform mathematical calculations. Here's a list of arithmetic operators that are supported in Python

| Operator | Function       | Syntax |
| -------- | -------------- | ------ |
| +        | Addition       | a + b  |
| -        | Subtraction    | a - b  |
| *        | Multiplication | a * b  |
| /        | Division       | a / b  |
| //       | Floor Division | a // b |
| %        | Modulo         | a % b  |
| **       | Power          | a ** b |


```python
a = 10
b = 4

# Addition
a + b
```


```python
# Subtraction
a - b
```


```python
# Multiplication
a * b
```


```python
# Division
a / b
```


```python
# Floor Division
a // b
```


```python
# Modulo
a % b
```


```python
# Power
a ** b
```

## String Operators

Some operators work differently on different types of data. For strings, the `+` operator will concatenate two strings together:


```python
line_1 = 'Good night! Good night! '  # <-- Note the space at the end of this string
line_2 = 'Parting is such sweet sorrow.'

# Concatenate two strings using the + operator
combined = line_1 + line_2
combined
```

The `*` operator can be used to duplicate a string and concatinate the results:


```python
hello = 'Hello! ' * 5
hello
```

Other operators won't work on strings, however, because the behavoir is not well defined. What would dividing one string by another produce? Power?

## List Operators

Similar to strings, the `+` operator can be used to combine two lists:


```python
list_a = ['A', 'B', 'C']
list_b = ['D', 'E', 'F']

combined = list_a + list_b
combined
```

The `*` operator can also be used with lists to duplicate the contents of a list many times:


```python
repeating_pattern = [1, 2, 3] * 3
repeating_pattern
```

# Exercise

The equation of a line is: 

\begin{equation}
\label{eq:sedov}
y = mx + b
\end{equation}

Use the arithmetic operators to calculate y given the following values for m, x, and b.


```python
# Given
m = 5
x = 10
b = 2

# Write your code here
y = None

# This code checks your code
if y != 52:
    print(f"I'm sorry, {y} is not the correct answer!")
else:
    print(f"{y} is correct!")
```

Given the following equation:

\begin{equation}
\label{eq:sedov}
c = \left(a^2 + b^2\right)^{0.5}
\end{equation}


Write the code to calcuate `c` given `a` and `b`


```python
# Given
a = 4
b = 3

# Write your code here
c = None

# This code checks your code
if c != 5.0:
    print(f"I'm sorry, {c} is not the correct answer!")
else:
    print(f"{c} is correct!")
```

b036a6388b87c2d041ebc6bc42bd82ae9249f4b4
ipynb
Jupyter Notebook
05 - Operators.ipynb
Aquaveo/python_basics
c0aef8332f88fa797aa1196c0fac678c3e2faf5a
MIT
05 - Operators.ipynb
Aquaveo/python_basics
c0aef8332f88fa797aa1196c0fac678c3e2faf5a
MIT
05 - Operators.ipynb
Aquaveo/python_basics
c0aef8332f88fa797aa1196c0fac678c3e2faf5a
MIT
Qwen/Qwen-72B
1. YES
2. YES