mike10101
mike10101

Reputation: 23

printing special characters without spaces

I made a for loop to write a little program that has an if condition. I want to print a number and put it between '' without any space. Here is a portion of my program :

for y in range(2):  

print('  if a ==','\'',y,'\'' ,'and',' b ==','\'',y,'\'',':')

My output is

but I want it to be :

without any spaces between the ' and the number.

Upvotes: 0

Views: 40

Answers (1)

letsc
letsc

Reputation: 2567

Elaborating on my comment. You can use + instead. However a much better way of "formatting" you print statements exactly the way you want is to use .format.

print ('If a == '{0}' and b == '{0}'.format(str(y)))

Upvotes: 2

Related Questions