Reputation: 23
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
if a == ' 0 ' and b == ' 0 ' :
if a == ' 1 ' and b == ' 1 ' :
but I want it to be :
if a == '0' and b == '0' :
if a == '1' and b == '1' :
without any spaces between the ' and the number.
Upvotes: 0
Views: 40
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