Python Forum
how can i print two value in single line
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how can i print two value in single line
#1
Dear ALL,

how can I print two valueS in a single line 

print(k )
print(v)

MY OUTPUT SHOULD BE 

Ontology: 3



THANK YOU
Reply
#2
use formatting:
pinrt('{}: {}'.format(k, v))
Reply
#3
Also, since python 3.6 you have formatted srings
print(f'{k}: {v}')
in any case you may want to look at format string syntax and the Template strings (not presented here - by Larz60+ or me)
Reply
#4
You can just print(a, b). But this is not the proper way to do it. See the other answers.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
As you say, it's not the proper way, then why you suggest it? Just to confuse newbies?
Reply
#6
He is asking how to print two values at once. It is not mandatory to include a string formating.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#7
(Feb-28-2017, 10:41 AM)wavic Wrote: He is asking how to print two values at once. It is not mandatory to include a string formating.

You are right - it's not manadtory. Actually there are at least 3 more ways to achieve what he asks for - concatenation, old-style %-formatting and str.join method. However, given the OP's inexperience better show him the generaly accepted and recommended, 'proper' way and not teach him bad habbits. :-)
Reply
#8
This is why I am not telling him to use my proposal.  Angel
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#9
(Feb-28-2017, 11:54 AM)buran Wrote:
(Feb-28-2017, 10:41 AM)wavic Wrote: He is asking how to print two values at once. It is not mandatory to include a string formating.

You are right - it's not manadtory. Actually there are at least 3 more ways to achieve what he asks for - concatenation, old-style %-formatting and str.join method. However, given the OP's inexperience better show him the generaly accepted and recommended, 'proper' way and not teach him bad habbits. :-)

Down with fundamentalism :). The simple version is completely fine for debugging. And to debug his/her code the OP will need plenty of throw-away print statements.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print on a single line with start/end brackets and commas Paulman 2 1,864 Oct-23-2021, 10:00 AM
Last Post: Paulman
  Reading a text until matched string and print it as a single line cananb 1 2,029 Nov-29-2020, 01:38 PM
Last Post: DPaul
  How to force print statement to print on one line wlsa 4 3,547 Oct-28-2018, 09:39 PM
Last Post: wavic

Forum Jump:

User Panel Messages

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