+ 1
Please how can i make use of the return keyword in python
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
+ 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!
+ 1
Tanks