How do you print 2 numbers in python?
This is just a snippet of my code: Show
But I want it to print out:
where
asked Mar 8, 2013 at 3:51
0 There are many ways to do this. To fix your current code using
A tuple with a single element looks like Here are some other common ways of doing it:
There's also new-style string formatting, which might be a little easier to read:
The clearest two, in my opinion:
answered Mar 8, 2013 at 3:52
BlenderBlender 280k52 gold badges426 silver badges487 bronze badges 7 There are many ways to print that. Let's have a look with another example.
answered Aug 11, 2016 at 13:07
Vikas GuptaVikas Gupta 10.3k4 gold badges30 silver badges42 bronze badges 1 Use:
Or:
Or:
Or:
Or:
Can use
answered Jan 18, 2018 at 11:23
In Python 3.6, In earlier version:
In Python 3.6:
will do. It is more efficient and elegant.
answered May 23, 2017 at 10:09
AbhishekAbhishek 4735 silver badges17 bronze badges Keeping it simple, I personally like string concatenation:
It works with both Python 2.7 an 3.X. NOTE: If score is an int, then, you should convert it to str:
answered Apr 1, 2015 at 20:57
Paolo RovelliPaolo Rovelli 9,0402 gold badges56 silver badges37 bronze badges Just follow this
OR
And forget all others, else the brain won't be able to map all the formats.
Wolf 9,3847 gold badges59 silver badges102 bronze badges answered Sep 22, 2017 at 7:11
TheExorcistTheExorcist 1,9091 gold badge18 silver badges25 bronze badges 1 Just try:
answered Jul 30, 2014 at 5:00
sarorasarora 5041 gold badge6 silver badges10 bronze badges Use
Or Use
answered Jul 7, 2018 at 6:08
M.InnatM.Innat 13.9k6 gold badges43 silver badges78 bronze badges 2
strickt01 3,8591 gold badge14 silver badges31 bronze badges answered Mar 3, 2016 at 16:51
If
If score is a string, then
If score is a number, then it's answered Jul 11, 2016 at 19:53
SupercolbatSupercolbat 3111 gold badge8 silver badges18 bronze badges This is what I do:
Remember to put a space after
answered Dec 21, 2015 at 9:51 The easiest way is as follows
Just put an "f" in front. answered Feb 14 at 16:35
This was probably a
Also! Run this
answered Jan 1, 2021 at 21:57 How do I print two numbers on one line in Python?To print on the same line in Python, add a second argument, end=' ', to the print() function call.
How do you use .2f in Python?2f is a placeholder for floating point number. So %d is replaced by the first value of the tuple i.e 12 and %. 2f is replaced by second value i.e 150.87612 .
...
Python String Formatting.. How do I print two variables on the same line?You can use the cat() function to easily print multiple variables on the same line in R. This function uses the following basic syntax: cat(variable1, variable2, variable3, ...) The following examples show how to use this syntax in different scenarios.
|