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
  • 97
  • 2
  • 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
  • 10,941
  • 4
  • 38
  • 59
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,400
  • 9
  • 16
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
  • 130,504
  • 14
  • 57
  • 93