Python Forum
how can i print two value in single line - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: how can i print two value in single line (/thread-2228.html)



how can i print two value in single line - desul - Feb-28-2017

Dear ALL,

how can I print two valueS in a single line 

print(k )
print(v)

MY OUTPUT SHOULD BE 

Ontology: 3



THANK YOU


RE: how can i print two value in single line - Larz60+ - Feb-28-2017

use formatting:
pinrt('{}: {}'.format(k, v))



RE: how can i print two value in single line - buran - Feb-28-2017

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)


RE: how can i print two value in single line - wavic - Feb-28-2017

You can just print(a, b). But this is not the proper way to do it. See the other answers.


RE: how can i print two value in single line - buran - Feb-28-2017

As you say, it's not the proper way, then why you suggest it? Just to confuse newbies?


RE: how can i print two value in single line - wavic - Feb-28-2017

He is asking how to print two values at once. It is not mandatory to include a string formating.


RE: how can i print two value in single line - buran - Feb-28-2017

(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. :-)


RE: how can i print two value in single line - wavic - Feb-28-2017

This is why I am not telling him to use my proposal.  Angel


RE: how can i print two value in single line - Ofnuts - Feb-28-2017

(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.