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.

2
  • Try this: roll + ‘.’ Commented Feb 21, 2021 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="") Commented Feb 21, 2021 at 18:42

3 Answers 3

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))
Sign up to request clarification or add additional context in comments.

2 Comments

print('The number is {}.'.format(roll)), if you use an older Python version.
Thank you much for this. Why does this work? What is the function of f before the string I want to print?
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}.")

Comments

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))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.