Calling already existing functions in Python

In this post I am going to explain how you need to use already existing functions in Python and I am going to demonstrate the use of them.

This site gives a clear overview of all the built-in functions in Matlab that you can use with an explanation what the function does. So that is a nice site to keep at hand while programming.

I am going to make the demonstration with the first function in the list: abs(). This function returns the absolute value of a number. It is for example useful for complex numbers:

Another example is the use of the function sum(). This function adds everything up in the variable that yout put in the functio. For example:

The both example above her are functions that are built-in in Matlab. So it is not necessary to import them from a Python module. There are also function that are not build-in and you have to import them. For example the function π, if you want to use π you need to import the module math. If you don’t do that you get the error that pi is not defined:

Therefore you need to import the module math (import math) and type math.pi instead of pi:

If you do it in this way, pi gives you the value of π . If you think that is is annoying to type math.pi, you can also on the way below. You get in this case the same information in your shell as in the example above

And the last thing that I want to explain is that you can also import your own modules. For example, for another assignment (WSQ02) I made a file. If you import that file (import WSQ02), you can use the information out of that file. That file contains information about Fahrenheit and degrees and you can use that as you can see in this example.

Hopefully you enjoyed reading my blog again and have you learned new stuff!


Plaats een reactie

Vul je gegevens in of klik op een icoon om in te loggen. logo

Je reageert onder je account. Log uit /  Bijwerken )

Google photo

Je reageert onder je Google account. Log uit /  Bijwerken )


Je reageert onder je Twitter account. Log uit /  Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit /  Bijwerken )

Verbinden met %s

Maak je eigen website aan bij
Aan de slag
%d bloggers liken dit: