Project 6: Calling Functions

--Originally published at TEC GDL 2016

Functions come up in every programming language. By using functions, a programmer is able to structure his/her program better because it enables them to write a code that can be used many times within the program (“block of organized, reusable code”). In that sense, it simplifies your program and once you are able to include functions within a program your programs not only looks better, but also gets more ‘simple’!
          *** (Remember Rule 3:’Simple is better than complex’, Zen of Python). ***

For the sake of this blog post I will only cover the main part of calling functions, because my next project will be about defining functions ourselves and then being able to call these. There are many functions installed within Python and are always available to be called by the program. This list was taken from the Python website itself and I hope it includes all the latest functions available (as Python sometimes adds/deletes functions):

Bildschirmfoto 2016-09-14 um 23.29.02.png

To explain all of these functions would take a long time, but if you are curious to see what the other functions do (those I don’t use in this post) please click !!HERE!!

I will try to explain how functions are called by using a calculator program I found really helpful. To exemplify how functions are called please look at the program below:

Bildschirmfoto 2016-09-15 um 00.00.27.png

In the program above, the built-in function “input” is used in order to “store a value” and use it later in your code. The programmer is able to use the input functions repeatedly, in order to store different values in the object you give them (e.g. ‘add1’, ‘sub2’ etc.). Additionally, also the “print” function is an example of a function built-in which we have been using from the first day of class onwards.

In the next blog post

?
will touch upon defining functions ourselves and using them also in a calculator program!

If you have any questions just hit me up!?

 

Sources:

http://sthurlow.com/python/lesson05/

http://www.tutorialspoint.com/python/python_functions.html