-8

How can i print without "\n" and with parameters

Example:

Print this : print("%d, %d" % (a, b)) without newline

I tried this (but don't work): print("%d, %d" % (a, b),end="")

I have this :

  File "./test.py", line 9
    print("%d, %d" % (a, b), end="")
                                ^                           
SyntaxError: invalid syntax
khelwood
  • 55,782
  • 14
  • 81
  • 108
APoorDev
  • 171
  • 1
  • 11

2 Answers2

0

Python 2.x:

from __future__ import print_function   # import the print func
print("{}, {}".format(1, 2), end="")   # 1, 2

Python 3.x:

print("{}, {}".format(1, 2), end="")   # 1, 2
DirtyBit
  • 16,613
  • 4
  • 34
  • 55
-2

To print and end it with a special character

print ('YOur message' , end = ' ') the end is by default \n and can be overridden

and your message string will be'{} {}'.format(a,b)

Completing it to print ('a = {}, b = {}'.format(a,b), end = ' ')

enter image description here

anand_v.singh
  • 2,768
  • 1
  • 16
  • 35