- 2

Help dont get this.

def print_double (x): print (2*x) print_double (3) why is the output 6. and what is print_double(2*x) also explain me print_double (3). thank you

16th Jan 2017, 7:11 PM
stephen haokip
stephen haokip - avatar
2 Respostas
+ 6
print double is a function where you insert a number , wich is x. So if you pass 3, remplace the x with 3. print_double(x): print (2*x) // wich is 3*2 = 6 same with print_double(2) = 2*2 = 4
16th Jan 2017, 7:18 PM
Nahuel
Nahuel - avatar
+ 3
1st line: the def keyword means that print_double is a function. That function has one parameter named 'x' as you can see between parenthesis. 2nd line: Here it says that the 'print' function will output the result of 2*x when the print_double function has been called with the rigth argument. So 'x' is the name but you don't know the value yet. 'x' is a placeholder, and could be any number (and any string too) that you pass as an argument. 3rd line: Here you call the print_double function and you pass it the value of 3 as an argument. So parameter 'x' now have 3 as the argument value you passed to rhe function. That's why the output will be 6, because it is 2*3. If you pass a character like "a", the output would be "aa", and that's because Python can be weird sometimes :)
16th Jan 2017, 7:46 PM
Iván
Iván - avatar