How to return myfunction in python3.? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 2

How to return myfunction in python3.?

How to return myfunction in python3.?

16th Nov 2017, 2:17 PM
Бондаренко Алексей Максимович
Бондаренко Алексей Максимович - avatar
1 Respuesta
0
Do you mean how to return a value from a function? it depends on the programming language you are using, e.g.: on Java the command 'return' gives you back the value returned from the function after you give some arguments and the function is executed. Code example: (difference with iteraction of increments) public static int myfunc (int x, int y) { int a = x; int b = y; while ( b > 0) { a = a + 1; b = b - 1; } } return a; // returns the value of the 'a' variable // after // myfunc is executed if we call this method with arguments (3,1) myfunc works like this: - in order to keep the original values of input, it 'copies' x and y values into two new variables, called a and b - then while b is > 0, it increments the value in a decrementing at the same time the value of b (so if at the first iteration, a is 3 and b 1, at the end of that, a is 2 and b is 0) - at the end of while loop, the result of the difference is into the variable a, so the function returns that value
16th Nov 2017, 2:32 PM
Federico Sanua
Federico Sanua - avatar