-2

Simple question but cannot find a simple solution. If I have this code:

print("I don't like",FavColour,", I prefer Red")

It prints:

I don't like FavColour , I prefer Red

How do I get rid of the space between FavColour and the comma , as I want my work to be grammatically correct. If I remove the commas, it becomes a syntax error.

freginold
  • 3,946
  • 3
  • 13
  • 28
Malhog
  • 1

3 Answers3

1

Either construct the entire string instead of passing pieces to print():

print("I don't like" + FavColour + ", I prefer Red")

or use print()'s sep argument to change the spaces to nothing:

print("I don't like",FavColour,", I prefer Red", sep='')
jwodder
  • 54,758
  • 12
  • 108
  • 124
0

Try:

print("I don't like " + FavColour + ", I prefer Red")
Eran
  • 844
  • 6
  • 20
0

You can combine Strings using the '+' sign, this way it will not print out an extra space. But if you are trying to print out a number/decimal you might have to cast it to a string using str(number/decimal) to convert it into a string. If this doesn't work let me know, I'm kind of rusty on Python.