Executing a Function
You may have seen functions like
round() already. These are called built-in functions because they are built into Python, and you can use them in your Python programs right away without adding any additional code. So they are perfect to investigate what functions actually are.
Let’s hop over to IDLE. First, I’ll show you how to use
type(), which is also a built-in function, to inspect the string and an integer. Then we’ll have a closer look at the
So if I type
type() at the top of this terminal.
So if I type
built-in function print, but an empty line. Okay, we’ll come back to this in a bit.
The error message that Python shows me says
TypeError: len() takes exactly
one argument, but
given. An argument is a value that gets passed to the function as input. Some functions can be called with no arguments, so like we saw with the
print() function, and some can take as many arguments as you like.
len() requires exactly one argument.
05:07 You’ve learned how to call functions, and you learned that they return a value when they’re done executing. Because I like emoji just as much as I like pancakes, I created this little illustration.
05:21 The waving hand stands for the function call. Then the cogwheel represents that the function is doing something. Finally, the function returned something for you. For this, I used an envelope because envelopes usually contain something of value.
So let’s try and say
print("Hello"). When we run it, then
Hello gets displayed in the Python shell again, but now we can check what
return_value is … and nothing is shown.
print() returns nothing?
Wouldn’t it be cool to have a
print() function that also returns the text value? Say no more. In the next lesson, you will learn how to create your own function that can actually return something.
Become a Member to join the conversation.