Python Forum
printing multiple results together
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
printing multiple results together
#1
I have a question, if I have multiple results and wanted to print the results together in the end of the code, what code should I use?
Reply
#2
for example

result1 = "Hello"
result2 = "World"

print("%s %s" % (result1, result2))
Output:
Hello World
Reply
#3
Very old, you should not use it, but knowing this formatting syntax is good.
There is much code outside from Python 2 era.
result1 = "Hello"
result2 = "World"
 
print("%s %s" % (result1, result2))
Instead you can use the format method:
result1 = "Hello"
result2 = "World"
 
print("{} {}".format(result1, result2))
Since Python 3.6 the 'f-string':
result1 = "Hello"
result2 = "World"
 
print(f"{result1} {result2}")
or just print the values without formatting a string:
result1 = "Hello"
result2 = "World"
 
print(result1, result2)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
(Sep-28-2019, 11:19 AM)Axel_Erfurt Wrote: for example
result1 = "Hello" result2 = "World" print("%s %s" % (result1, result2))
Output:
Hello World
Thank you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Search Results Web results Printing the number of days in a given month and year afefDXCTN 1 2,231 Aug-21-2020, 12:20 PM
Last Post: DeaD_EyE
  Random nr. no repetition & printing multiple lines Joey 7 2,788 Feb-05-2020, 04:23 PM
Last Post: Larz60+
  How to append one function1 results to function2 results SriRajesh 5 3,141 Jan-02-2020, 12:11 PM
Last Post: Killertjuh
  How to execute a string with multiple sqlite statements and print results? shanepy 0 2,260 Nov-20-2018, 10:19 PM
Last Post: shanepy
  Creating multiple text fies from new url retrieve results wmc326 1 3,122 Jul-13-2017, 10:57 PM
Last Post: Larz60+
  Multiple Question Results code flynnmackie 2 74,523 Mar-13-2017, 06:54 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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