Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
return variable in func
#1
#!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?
Reply
#2
you're not assigning the return value to anything:
word2(word)
it needs a home:
newword = word2(word)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to output one value per request of the CSV and print it in another func? Student44 3 1,278 Nov-11-2022, 10:45 PM
Last Post: snippsat
  Func Animation not displaying my live graph jotalo 0 1,521 Nov-13-2020, 10:56 PM
Last Post: jotalo
  Trying to write func("abcd") -> "abbcccdddd" omm 8 3,983 Oct-24-2020, 03:41 AM
Last Post: bowlofred
  Function will not return variable that I think is defined Oldman45 6 3,435 Aug-18-2020, 08:50 PM
Last Post: deanhystad
  [split] script: remove all "carriage return" from my json variable pete 2 2,743 May-05-2020, 03:22 PM
Last Post: deanhystad
  call func from dict mcmxl22 3 2,820 Jun-21-2019, 05:20 AM
Last Post: snippsat
  About [from FILE import FUNC] Nwb 7 3,522 Apr-21-2019, 02:46 PM
Last Post: snippsat
  script: remove all "carriage return" from my json variable mfran2002 4 11,087 Feb-20-2019, 05:07 AM
Last Post: mfran2002
  Executing func() from a different folder ebolisa 2 2,306 Jan-14-2019, 10:18 AM
Last Post: ebolisa
  Correct number wrong position func. albry 5 5,956 Jan-11-2019, 04:01 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020