# Python, Beginner Level (My Study Notes)

Last Update: 2018-12-12 What programming language should you learn? My answer is Python. Would you like to learn Machine Learning/ Statistics/ Data Analysis or...in the near future? It doesn't matter what's your purpose, if you need to work with figures and data, you can get benefit from this easy-to-learn and easy-to-use programming language.

# Math Functions

Chapter 9- Python, Beginner Level (My Study Notes)

Last Update: 2018-12-12

Description
The math function is under math module. Thus, you need to import math module before you com use it.

Content

The math function is under math module. Thus, you need to import math module before you com use it.
>>>import math

Now, you can use the functions provided by math module.

math functions are called in following way:

math.function_name()

Specify the module name + '.' + function name
This is called dot notation.

For instance, we need to use the log function, so:

math.log()

>>> x=math.log(5)
>>> print(x)
1.6094379124341003 After you typed

math.

a select box appears, you can see all math module functions. The select box sometimes appears late.
Create a function

Create a function is handy, you just need to use the following format:

def  function_name:

def = define a function

Then, give it a space before the function name.

Finally end it with colon(:)

For instance, I would like to create a function for doing a multiplication, I give the function name calculateIt. The function needs to have 2 arguments, a and b, then, the function return c. The c is the  product of a and b.

* =  multiplication sign

>>> def calculateIt(a,b):
c=a*b
return c

>>> print(calculateIt(3,5))
15

The first line of the function is called the header:

def calculateIt(a,b):

and the rest of the function is called the body:

c=a*b
return c
After you typed

math.

a select box appears, you can see all math module functions. The select box sometimes appears late.
Create a function

Create a function is handy, you just need to use the following format:

def  function_name:

def = define a function

Then, give it a space before the function name.

Finally end it with colon(:)

For instance, I would like to create a function for doing a multiplication, I give the function name calculateIt. The function needs to have 2 arguments, a and b, then, the function return c. The c is the  product of a and b.

* =  multiplication sign

>>> def calculateIt(a,b):
c=a*b
return c

>>> print(calculateIt(3,5))
15

The first line of the function is called the header:

def calculateIt(a,b):

and the rest of the function is called the body:

c=a*b
return c

### Arguments and Parameters

Both terms sometimes are confusing.

Using the above example:

def calculateIt(a,b):

a and b are argument which the function calculateIt takes them. Inside the function a and b are parameters for doing a multiplication. The product c is a parameter as well.

The print() which allows to print something more than one:

>>> print('echo '*5)
echo echo echo echo echo

It printed echo 5 times.