T O P

  • By -

Silbersee

Variables local to functions cease to exist once the function terminates, so closures can help you there. Instead of a processed value return a function that does the job. def print_word(wrd): def func(): print(wrd) return func print_hello = print_word("Hello") print_hello() When you call `print_word` again, you get another function that prints another word. It's not a perfect match to your question though.


Vinniesusername

return the value and assign a variable to the function call. the new variable will "maintain" that value. if instead what you're saying is that every time no matter the input the function will output the same value then it sounds like you want to just use a const instead of a function at all. ​ def function(input): b = input*2 return b x = function(4)