2

I want to print few words followed by a int followed by few words again followed by a big int in python. How can we do it... Like in c++, we do:

cout<<" "<<x<<" "<y

where x and y are integers.

Ashwini Chaudhary
  • 232,417
  • 55
  • 437
  • 487
Nikhil Garg
  • 129
  • 1
  • 7
  • Have you tried anything? Have you done any [research](http://stackoverflow.com/questions/15286401/print-multiple-arguments-in-python)? – Henry Keiter Sep 25 '13 at 17:19

3 Answers3

2

There are several ways, just to mention a few:

# Python 2.x

print 'before', 42, 'after'
print 'before ' + str(42) + ' after'
print '%s %d %s' % ('before', 42, 'after')  # deprecated
print '{} {} {}'.format('before', 42, 'after')

# Python 3.x

print('before', 42, 'after', sep=' ')
print('before ' + str(42) + ' after')
print('%s %d %s' % ('before', 42, 'after')) # deprecated
print('{} {} {}'.format('before', 42, 'after'))

All of the above statements will produce the same result on-screen:

=> before 42 after
Óscar López
  • 225,348
  • 35
  • 301
  • 374
0

You can do it this way:

print 'word %s word word' % 42
Michael
  • 14,053
  • 33
  • 90
  • 141
0

Something closer to C

i = 34
x = 56
print "Integer i = %d and integer x = %d" % (i,x)
jramirez
  • 8,201
  • 7
  • 31
  • 46