0
About def and return
after 3 months learn python, learning oop, create many project, but i never understand about return in function. def okay(msg): python = 'programming language' nice = print('you are ' + str(msg)) return python okay('good') print(python) #error so how to print python?
3 Respostas
+ 2
You can access the returned value if you declare the variable as global in your function definition:
def okay(msg):
global python
python = 'programming language'
nice = print('you are ' + str(msg))
return python
okay('good')
print(python)
# output:
# you are good
# programming language
see, e.g. https://www.google.ca/amp/s/pythontips.com/2013/07/28/the-use-of-return-and-global-keywords/amp/
0
def okay(msg):
python = 'programming language'
nice = print('you are ' + str(msg))
return python
print(okay("good"))
output-->
you are good
programming language...
suppose
def hi(x):
......
......
......
return 6
##this means...
##hi(x) = 6
print(hi(7))
print(hi(78))
print(hi(0.6))
every print will print 6
0
good explanation.thnx.
but in tutorial, its said: return can make something useable later.
something wrong about you:
it will not print python because its in variable
just wonder how can i print python outside function