Function arguments
We're going to explore how to receive parameters and operate with them in your functions. In the editor you'll see a simple function that accepts just one parameter (named x
in this case). This function's job is to multiply x
by 2 and return the result. For example, if we pass 3 as the parameter, we're going to receive 3 * 2
as the result:
multiply_by_two(3) # 6
Parameters are matched by position. In this case multiply_by_two
receives only one parameter (x
), so when we invoke it passing the number 3
, it gets assigned to x
.
Now go ahead and try implementing the multiply_by_two
function by yourself.
Solution 1
def multiply_by_two(x):
return x * 2