Skip to main content

3.7) Using Functions


Here, we’ve introduced a function called 'type()'. A function is a piece of code which takes in some input, called arguments, performs some tasks with the input, and can return a value. Here’s how you call a function:

>>> result=function_name(argument1,argument2,...)

Sometimes arguments are optional and some functions don’t return any value (result would have the value None). You might call your function in this way (e.g. without any arguments if there are default values already set):

>>> function_name()

Python provides some in-built functions; type() is one of them. The type() function takes in an object, such as an integer, and returns some text describing its type. So the general way to use it is:

>>> result=type(3)
>>> print result
<type 'int'>

You can also write your own function. We’ll see how to do this later on in this course.