Is there any way to exclude the automatic space that appears after the comma in python?

4

A brief example:

zero = 0
print('exemplo',zero)

The program shows:

  

example 0

I wanted without the space:

  

example0

    
asked by anonymous 26.09.2017 / 11:25

1 answer

10

In this exact way, print('exemplo',zero) , no.

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

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

DOCS

Here are other ways to do this:

zero = 0
  • Format

    print('exemplo{}'.format(zero))
    
  • + sign

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

    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

        
    26.09.2017 / 11:51