Issue
I tried to modify the value of a string inside a function, like below:
>>> def appendFlag(target, value):
... target += value
... target += " "
...
>>> appendFlag
<function appendFlag at 0x102933398>
>>> appendFlag(m,"ok")
>>> m
''
Well, seems the "target" is only changed within the function, but how to make the new value viable outside the function? Thanks.
Solution
This is handled in python by returning.
def appendFlag(target, value):
target += value
target += " "
return target
you can use it like this:
m = appendFlag(m,"ok")
you can even return several variables like this:
def f(a,b):
a += 1
b += 1
return a,b
and use it like this:
a,b = f(4,5)
Answered By - Christian Sloper
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.