+ 1
Def function in python
Can anyone please explain me what actually (def) and (return ) function do?
7 odpowiedzi
+ 6
Lothar, it is strange that the links crashes the apps...
Vivek Maurya, as Lothar already said, "def" and "return" are keywords for python.
"def" is used to define a function, and "return" is used to return a value which is produced by the function.
While a function can accept zero input, most of the time it accepts inputs and produce output.
Take an analogy, a water boiler is a function. Fresh water is the input and hot water is the output. Some mechanic inside the boiler is the code inside a function, and you have a cup to hold the hot water. So a "boil_water" function will look something like this:
def boil_water(fresh_water):
hot_water = heat the fresh_water
return hot_water
cup_of_water = boil_water(some_water)
And here is another example which return a value by increasing 10 from the input.
def add10(num):
result = num + 10
return result
my_num = add10(5) # 15
+ 8
Vivek Maurya ,
your post seems to be incomplete since it lacks of some basic information. (programming language, your code attempt, ...)
it looks like you are searching (in python) for more details about *creating functions* and their usage, as well as the using of the *return* statements.
(def and return are not functions but statements / keywords)
these topics are part of the python tutorials. you may re-reading these topics and do some exercises with it.
if you still get stuck, post specific questions here.
here are some additional learning sources from the community section about functions in python:
https://www.sololearn.com/learn/o-Python/2285/?ref=app
https://www.sololearn.com/learn/o-Python/2287/?ref=app
+ 3
Wong Hei Ming ,
the 2 links i provided are working properly for me on android app. what issue do you get exactly?
+ 2
Wong Hei Ming ,
there is no problem on my galaxy tab s6 lite.
the current android version is 13, so may be you can update your device ...
+ 1
Lothar
It displays the page for less than a second, then it crashes and saying "SoloLearn keeps stopping."
It happens on my Nokia 7.2 (Android 11) and Amazon Fire HD 10 (Fire OS 7.3.2.9)
If I make a search from the community tab, it is not always keep stopping. It is like some pages crash and some don't. Can't figure it out...
+ 1
Lothar
Nokia 7.2 was released at end of 2019, and it became EOL by end of 2022, so I don't receive update anymore. Unless I unlock and fresh it with custom rom, which I don't feel comfortable to do with my daily working horse.
0
Vivek Maurya ,
Learn these terms (Sololearn doesn't teach them):
compound statement
clause
header
suite
"Function and class definitions are also syntactically compound statements." -- https://docs.python.org/3/reference/compound_stmts.html#compound-statements