+ 1

Please how can i make use of the return keyword in python

26th Jun 2019, 11:21 PM
Ogoh Augustine
Ogoh Augustine - avatar
3 Respostas
+ 2
in python, there's no such function as 'return'. 'return' is already a keyword. However, you could use 'return' to generate a value and immediately exit a function thereby 'return-ing ' from that function. Here's a simple function that 'returns' the value of a multiplication def multiply(a, b): return a*b result = multiply(2, 5) print(result) //outputs 10 When the above statement is executed, the multiply function 'returns' the value 2*5, that value is then stored in the 'result' variable, which is then printed out
26th Jun 2019, 11:29 PM
Dlite
Dlite - avatar
+ 2
1: You can use it to return a value. 2: You can use it as stronger break statement (break statements would only break the innermost loop). def w(): while True: while True: while True: while True: while True: return "Hahaa, broken 5 while loops once!" x = w() print(x) #Output: Hahaa, broken 5 while loops once!
27th Jun 2019, 1:33 AM
Seb TheS
Seb TheS - avatar
+ 1
Tanks
26th Jun 2019, 11:30 PM
Ogoh Augustine
Ogoh Augustine - avatar