Removing space between an integer and fullstop

Question:

I want to remove space between an integer and a full stop.

sol=(num1+num2)*(num1+num2)
print("nThe Solution is",sol,'.')

Here output is The Solution is 5 .
I want The solution is 5.
I want to remove space between 5 and fullstop.

Asked By: Waseem Munir

||

Answers:

Simply change your code to :

sol=(num1+num2)*(num1+num2)
print("nThe Solution is",str(sol) + '.')
Answered By: marc

This should do it:

    sol=(num1+num2)*(num1+num2) 
    print(f"nThe Solution is {sol}.")

More about f-strings: https://realpython.com/python-f-strings/#python-f-strings-the-pesky-details

Answered By: Anuvrat Parashar

You can try with format function
In brackets “{}” is a place holder for a value. In format, you specify the value , which is your sol variable

sol=(1+2)*(1+1)

print("nThe Solution is {}.".format(sol))

Outputs :

The Solution is 6.

Another, shorter version would be using f string. You put f before text string & specify your variable in brackets {}

print(f"nThe Solution is {sol}.")

Outputs :

The Solution is 6.
Answered By: Vladyslav Didenko
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.