close

How to print variables without spaces between values

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to print variables without spaces between values in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to print variables without spaces between values?

  1. How to print variables without spaces between values?

    Just an easy answer for the future which I found easy to use as a starter: Similar to using end='' to avoid a new line, you can use sep='' to avoid the white spaces…for this question here, it would look like this: print('Value is "', value, '"', sep = '')

  2. print variables without spaces between values

    Just an easy answer for the future which I found easy to use as a starter: Similar to using end='' to avoid a new line, you can use sep='' to avoid the white spaces…for this question here, it would look like this: print('Value is "', value, '"', sep = '')

Method 1

Don’t use print ..., (with a trailing comma) if you don’t want spaces. Use string concatenation or formatting.

Concatenation:

print 'Value is "' + str(value) + '"'

Formatting:

print 'Value is "{}"'.format(value)

The latter is far more flexible

You’ll also come across the older % formatting style:

print 'Value is "%d"' % value
print 'Value is "%d", but math.pi is %.2f' % (value, math.pi)

but this isn’t as flexible as the newer str.format() method.

In Python 3.6 and newer, you’d use a formatted string (f-string):

print(f"Value is {value}")

Method 2

Just an easy answer for the future which I found easy to use as a starter: Similar to using end='' to avoid a new line, you can use sep='' to avoid the white spaces…for this question here, it would look like this: print('Value is "', value, '"', sep = '')

May it help someone in the future.

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read