+ 1
Can someone explain me 'return' in python?
In one of my programs, when I use return nothing happens. I don't speaks English, so sorry for mistakes
9 Réponses
+ 6
I think you have called the function, but did not store the returned data in a variable. you can do like this:
def rule(dit):
dit = list(dit)
dit.append(dit[0])
dit.append("ay")
del dit[0]
return (dit)
res = rule('hello')
print(''.join(res))
# the last 2 lines can be put together:
print(''.join(rule('hello')))
+ 3
it is used in functions.
a function is like a cigarette automate:
you give money, it returns cigarettes
a function gets data.. or not
and returns data or none
+ 3
Lothar normal vergleiche ich mit nem Kaffeautomat.
Da würde ich jetztsagen:
Stell nen Becher drunter 😊
+ 1
Thanks but looks that:
def rule(dit):
dit = list(dit)
dit.append(dit[0])
dit.append("ay")
del dit[0]
return (dit)
When I try to call the function, nothing happens. I don't understand why...???
+ 1
In functions return will return a value from that function and it will not appear without print fonction.But return without given values in function tell the interpreter to return to the begin of the code and execute nothing within current function.
With return a value:
def function(a):
return a*2
X = function(9)
print(x) ==> 18
0
Can you show the code.. So it helps what you are troubling with..!!!
return returns to calling statements with returning returned values or none returning...
Edit :
you are not calling the function.. Lagouth007
You have only function definition and you need to use it to work with it..
0
Thanks Lothar 😊
0
example:
def ex(user):
if user=="Your name":
return("okay your name")
else:
return("?")
user = input("What is the word:")
print(ex(user))
0
the return keyword basically means you can store the data you return to a variable by calling the function. Wether that is a bool, a float, a int or a class
example:
def val():
return 5
a = val()
here, a = 5.