Python Forum
Error with print and return commands
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error with print and return commands
#1

Hello guys, I'm new to Python, just tried running a simple code but am facing an error. Here's how my code looks like-

def f(x):
    return x+10
    print "wOw"
And here's the output:
f(73)
output--> 83

Why does it not print what I have written after the return command, in my code?

Would appreciate suggestions. This is my first message , sorry for mistakes if any, and feel free to point them out. Thanks.
Reply
#2
The return keyword terminates the function. You'll need the print() call prior to return.
Reply
#3
(Jan-15-2020, 04:06 PM)stullis Wrote: The return keyword terminates the function. You'll need the print() call prior to return.

Thanks for the response. This helped me learn a new thing.
However, does it mean that it's never possible to have an output consisting of a number + text, using the return command? For e.g. 10 chocolates?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Receiving this error in my "response" and causes script to return wrong status cubangt 18 1,910 Aug-13-2023, 12:16 AM
Last Post: cubangt
  Print Error DaveG 1 1,062 Apr-07-2022, 03:10 AM
Last Post: deanhystad
  return vs. print in nested function example Mark17 4 1,674 Jan-04-2022, 06:02 PM
Last Post: jefsummers
  return out of loops syntax error felixf 7 3,354 Nov-03-2020, 01:00 PM
Last Post: perfringo
  SystemError: error return without exception set!!! faryad13 3 3,583 Oct-23-2020, 02:32 PM
Last Post: ATARI_LIVE
  syntax error on return statement l_butler 5 3,026 May-31-2020, 02:26 PM
Last Post: pyzyx3qwerty
  output while using return instead of print muza 2 2,092 Apr-23-2020, 09:38 AM
Last Post: muza
  I am getting an Error, and not sure why? My goal is to print out rahulne22 7 2,978 Dec-01-2019, 03:53 PM
Last Post: snippsat
  Python Error 'return self.attrs[key]' Need help! ahmedwaqas92 0 4,363 Oct-13-2019, 03:50 AM
Last Post: ahmedwaqas92
  Embedding return in a print statement Tapster 3 2,233 Oct-07-2019, 03:10 PM
Last Post: Tapster

Forum Jump:

User Panel Messages

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