# Python Tutorial 3: Basic Operation

## 1. Quick Math

Remember first learning about Maths in primary school? It is similar in Python.

Commonly used operators:

Symbol Meaning
+ Addition
Subtraction
* Multiplication
/ Division
** Exponential
% Modulus (returns the remainder)
In :
```a = 2
b = 2
```
In :
```sumofAB = a+b
print(sumofAB)
```
```4
```
In :
```c = 1
minusC = sumofAB - c
print(minusC)
```
```3
```
In :
```multiplyAB = a * b
print(multiplyAB)
```
```4
```
In :
```divide = a / b
print(divide)
```
```1.0
```
In :
```exponential = a ** b
print(exponential)
```
```4
```
In :
```WhatIsTheReminder = b % a
print(WhatIsTheReminder)
```
```0
```

## 2. String Operations

The ‘+’ operator behaves differently when it comes to strings. Instead of ‘addition’, we call this ‘concatenation’.

In :
```c = "2"
d = "3"
```
In :
```print(c + d)
```
```23
```
In :
```x = "Hello"
y = "World!"
print(x + " " + y)
```
```Hello World!
```

If we had concatenated x and y without adding the white space in between the following will be the result:

In :
```print(x + y)
```
Out:
`'HelloWorld!'`

### Concatenating strings with integers

We cannot concatenate strings with integers. To do so we need to convert the integer to a string, using the function str().

In :
```e = 23
print(c + d + str(e))
```
```2323
```

Similarly, in order to add a string (which is a number) to an integer, we can also convert the string to an integer using int().

In :
```print(int(c) + int(d) + e)
```
```28
```

# Try it out!

Assign 100 to principal, 1.05 to rate and calculate the product. Then, concatenate the output with “At the end of the year, I would have \$” and print the result.

In :
```principal = 100
rate = 1.05
print("At the end of the year, I would have \$" + str(principal*rate))
```
```At the end of the year, I would have \$105.0
```

# 3. Logical operators

In the previous chapter we covered some of the commonly used logical operators, which will return either True or False.

Here are more logical operators.

### Equal to? Not Equal to?

‘!=’ is the opposite of ‘==’. It means not equal to.

In :
```x = 6
print(x != 6)
```
```False
```
In :
```print(x != 8)
```
```True
```

### Is something inside a string?

We can find out whether a substring is present in another string using the ‘in’ operator. While this may sound redundant for now, it is useful to find whether a certain element is present in a list. You will more about lists in the next chapter.

In :
```a = 'at'
b = 'bat'
c = 'bath'
```
In :
```print(a in b)
```
```True
```
In :
```print(b in c)
```
```True
```
In :
```print(c in a)
```
```False
```

Putting ‘not’ in the boolean expression will return the opposite output.

In :
```print(a not in b)
```
```False
```
In :
```print(b not in c)
```
```False
```
In :
```print(c not in a)
```