1

print ("The number is", (roll),'.')

The number is 5 .

I want to remove the space between '5' and '.'

I have tried a few different methods to remove the space before the period, but I am either getting errors or the same result.

KV1
  • 65
  • 7
  • Try this: roll + ‘.’ – shauli Feb 21 '21 at 18:35
  • For everyone else like me who's surprised by this: the default separator for multiple parameters in print function is a space, because of which it was adding spaces between each element. You can override this using print(... , sep="") – Swetank Poddar Feb 21 '21 at 18:42

3 Answers3

1

You need a string formatting method or concatenating methods. the follwoing will give you same results


print (f"The number is, {roll}.")
print ("The number is, {}.".format(roll))
print ("The number is"+' '+ str(roll) +'.')
print ("The number is %s. "%(a))
Ade_1
  • 1,480
  • 1
  • 6
  • 17
  • `print('The number is {}.'.format(roll))`, if you use an older Python version. – Darius Feb 21 '21 at 18:38
  • Thank you much for this. Why does this work? What is the function of f before the string I want to print? – KV1 Feb 21 '21 at 18:39
1

There are multiple solutions to your problem. I can recommend f-strings.

print ("The number is", (roll),'.')

becomes

print(f"The number is {roll}.")

JK31
  • 55
  • 1
  • 5
1

There are multiple solutions to your question one of the solution you can do by using .format function.

print ("The number is {}.".format(roll))

Karim
  • 400
  • 1
  • 4
  • 13