1

In a code:

a = 6
for i in range(a):
    print("case #",i)

While printing the output, as shown below:

case # 0
case # 1
case # 2
case # 3
case # 4
case # 5

There is an extra space between '#' and the variable 'i'. How to remove this space? In fact, if we normally write:

a = 'sam'
print("hello",a)

then also, the output is:

hello sam

there is an extra space between "hello" and "sam". How to remove this?

VIKAS RATHEE
  • 87
  • 1
  • 13

3 Answers3

1

Try this:

print("hello",a , sep='')

sep is the separator of print function when you call in with more that one argument.

Mehrdad Pedramfar
  • 9,989
  • 4
  • 33
  • 55
1

You can just make one string from the two arguments, using +. Note: you have to convert i to string first.

a = 6
for i in range(a):
    print("case #"+str(i))
Piotrek
  • 1,290
  • 8
  • 15
1

Could you please try following too once.

a=6
for i in range(a):
   print 'case #%d' % (i)

Output will be as follows.

case #0
case #1
case #2
case #3
case #4
case #5
RavinderSingh13
  • 117,272
  • 11
  • 49
  • 86