-1

I am using Geany to code and Ubuntu 16.04 as my OS. when I enter this code

print("Result:",a+b)

It gives it's output as ('Result:', a+b).

pfnuesel
  • 14,093
  • 14
  • 58
  • 71
  • Where does this happen? Are you running your script from within geany, or the cli ? – deepbrook Sep 02 '16 at 11:27
  • `print "Result:",a+b` It will work in python 2.7.6 – Kalpesh Dusane Sep 02 '16 at 11:27
  • how about this: `print("{!s}{}".format('Result:', a+b))` – Ma0 Sep 02 '16 at 11:28
  • 3
    You're apparently using python2, in which "print" is a statement instead of a function. In your case the statement prints the [representation of the 2-tuple](http://stackoverflow.com/questions/7784148/understanding-repr-function-in-python) `("Result", a+b)`. Concider using python3. – Ilja Everilä Sep 02 '16 at 11:28
  • Or `from __future__ import print_function` to use the `print` function in Python 2. – chepner Sep 02 '16 at 14:08

1 Answers1

0

In python 2:

print("Result:",a+b) --> # ('Result:', 6)

parens are no needed, because otherwise we are printing a tuple of two elements: string 'Result' and an integer 6.

In python 3:

print("Result:",a+b) --> # Result: 6

parens are needed, just because print is a function instead of a statement in python 3.

So to do it the same in python 2 which is in python 3, you have to do this:

print "Result:", a+b --> # Result: 6
turkus
  • 4,637
  • 2
  • 24
  • 28