Python Forum
Embedding return in a print statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Embedding return in a print statement
#1
First, I hope I used the format/rules correctly.
I did a search for "embedding return in a print statement" before posting. I don't have the terminology down and may not be asking a syntactically correct question. If that's not a proper way to word the question I'm asking, please identify the correct way to word it if you would.
The last line of the code gives me the correct return. I want that same return embedded in the previous print statement but don't know the correct structure and would be appreciative of knowing/seeing it.
Thanks in advance.

print("Word Counter")
print("The purpose of the word counter is to enter the count of the number of words in a sentence entered into the system by the user.")
sentence = input("Enter the sentence you would like to test. When done, press Enter."'\n')
print("The sentence you entered is:") 
print(sentence)
print("In your sentence, the number of words is: (len(sentence.split(' ')))")
print(len(sentence.split(' ')))
Reply
#2
You don't have a function there. All return statements must be in a function (or method). Also, return is a statement, print is a function. You can't have a statement in a function call, only expressions.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Perhaps you mean
print("In your sentence, the number of words is:", len(sentence.split(' ')))
Reply
#4
That was the structure I was looking for Grib. Thanks.

ichabod:
If I had used the term output in place of return would you have given me a different answer. If not, I'm not sure what your trying to tell me.

Thanks to both of you for taking the time and adjusting my thought process.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to invoke a function with return statement in list comprehension? maiya 4 299 Jul-17-2021, 04:30 PM
Last Post: maiya
Question Embedding a python file online Dreary35 0 195 Jun-10-2021, 05:05 PM
Last Post: Dreary35
  Why doesn't this print statement work? stylingpat 10 1,012 Mar-23-2021, 07:54 PM
Last Post: buran
  Runs perfect in Python but fails to print last statement when converted to .exe. Help sunil422 3 728 Aug-13-2020, 01:22 PM
Last Post: deanhystad
  Need help merging/embedding duckredbeard 10 1,051 Aug-13-2020, 04:48 AM
Last Post: duckredbeard
  syntax error on return statement l_butler 5 963 May-31-2020, 02:26 PM
Last Post: pyzyx3qwerty
  output while using return instead of print muza 2 904 Apr-23-2020, 09:38 AM
Last Post: muza
  Taking brackets out of list in print statement pythonprogrammer 3 1,021 Apr-13-2020, 12:25 PM
Last Post: perfringo
  return statement will not work TheTechRobo 2 884 Mar-30-2020, 06:22 PM
Last Post: TheTechRobo
  capture print statement written in Stored Procedure in SQL Server brijeshkumar_77 0 961 Feb-18-2020, 03:22 AM
Last Post: brijeshkumar_77

Forum Jump:

User Panel Messages

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