return variable in func - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: return variable in func (/thread-8628.html) |
return variable in func - mepyyeti - Mar-01-2018 #!usr/bin/env python3 #ufunc0.py import sys def word2(a): a1= a+a print(a1) return a1 while True: move = input('\'g\' to start\nsomethingelse to quit >> ') move = move.lower().strip() if move != 'g': sys.exit() else: word = input('enter 1 word.') word = word.lower().strip() word2(word) print(a1)my understanding of return is that once I return a variable it should be usable outside. Regarding my last line, what am I getting wrong...(it really shouldn't need to be defined outside the function). It's in memory, no? RE: return variable in func - Larz60+ - Mar-01-2018 you're not assigning the return value to anything: word2(word)it needs a home: newword = word2(word) |