Python Forum

Full Version: return variable in func
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
#!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?
you're not assigning the return value to anything:
word2(word)
it needs a home:
newword = word2(word)