+ 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

5th Oct 2020, 1:35 PM
Lagouth007
Lagouth007 - avatar
9 Respostas
+ 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')))
5th Oct 2020, 1:48 PM
Lothar
Lothar - avatar
+ 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
5th Oct 2020, 1:39 PM
Oma Falk
Oma Falk - avatar
+ 3
Lothar normal vergleiche ich mit nem Kaffeautomat. Da würde ich jetztsagen: Stell nen Becher drunter 😊
5th Oct 2020, 1:50 PM
Oma Falk
Oma Falk - avatar
+ 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...???
5th Oct 2020, 1:41 PM
Lagouth007
Lagouth007 - avatar
+ 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
5th Oct 2020, 1:43 PM
HBhZ_C
HBhZ_C - avatar
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..
5th Oct 2020, 1:41 PM
Jayakrishna 🇮🇳
0
Thanks Lothar 😊
5th Oct 2020, 2:00 PM
Lagouth007
Lagouth007 - avatar
0
example: def ex(user): if user=="Your name": return("okay your name") else: return("?") user = input("What is the word:") print(ex(user))
6th Oct 2020, 5:49 PM
Cleen
Cleen - avatar
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.
7th Oct 2020, 1:31 PM
Sausty
Sausty - avatar