Is there any way to delete the auto space that appears after the python comma?

Asked

Viewed 564 times

4

A brief example:

zero = 0
print('exemplo',zero)

The program shows:

example 0

I wish without the space:

exemplo0

1 answer

10

In that exact way, print('exemplo',zero), nay.

But the way (only available in python3.x) more like this, in which space is taken out is:

zero = 0
print('exemplo', zero, sep='') # exemplo0

DOCS

Here are other ways for that to happen:

zero = 0
  1. Format

    print('exemplo{}'.format(zero))
    
  2. Sign of +

    print('exemplo' +str(zero)) # aqui, se ja for string escusas de usar str(...)
    
  3. %

    print('exemplo%d' % zero)
    

DEMONSTRATION

You can also create your own print() for things like this:

def my_print(*args):
   print(*args, sep='')

zero = 0
my_print('example', zero, 1, 2, 'olá') # example012olá

DEMONSTRATION

Browser other questions tagged

You are not signed in. Login or sign up in order to post.