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
  • 244,495
  • 58
  • 464
  • 504
Nikhil Garg
  • 129
  • 1
  • 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
  • 232,561
  • 37
  • 312
  • 386
0

You can do it this way:

print 'word %s word word' % 42
Michael
  • 15,386
  • 36
  • 94
  • 143
0

Something closer to C

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