Fintech
Fintech

Reputation: 21

Python Newbie Combine Text

How would I remove the space after the equals sign? I searched all over google and could not find anything on how to do it. Anyhelp would be greatly appreciated.

Code
    customer = input('Customer Name:')
    mpid = input('MPID=<XXXX>:')
    print ('description' ,customer,'<MPID=',mpid+'>')

Output
    Customer Name:testcustomer

    MPID=<XXXX>:1234

    description testcustomer <MPID= 1234>

Upvotes: 1

Views: 95

Answers (4)

Jordan
Jordan

Reputation: 4628

print(a, b, c) puts a into the output stream, then a space, then b, then a space, then c.

To avoid the space, create a new string and print it. You could:

concatenate strings: a + b + c

better: join strings: ''.join(a, b, c)

even better: format a string: 'description {0} <MPID={1}>'.format(customer, mpid)

Upvotes: 0

dansalmo
dansalmo

Reputation: 11686

Since the title is general, I thought this might be helpful to some even though it is not directly related to the full question:

The interpreter combines text strings (but not refences to strings) when they are next to each other on the same line or continued line.

>>>'this sen'   "tence w"                  '''ill be combined'''
'this sentence will be combined'

This allows line breaks and white space in long strings to improve readability without making the program have to deal with reassembling them.

>>>('1
     2
     3
     4')
'1234'

Upvotes: 0

ChrisP
ChrisP

Reputation: 5942

Here are some ways of combining strings...

name = "Joel"
print('hello ' + name)
print('hello {0}'.format(name))

So you could use any of these in your case...

print('description', customer, '<MPID={0}>'.format(mpid))
print('description {0} <MPID={1}>'.format(customer, mpid))

Upvotes: 3

Dolphiniac
Dolphiniac

Reputation: 1792

print ('description',customer,'MPID='+str(mpid)+'>')

I'd think this is what you'd do. You've already done that no-space concatenation with the closing angle bracket.

Upvotes: 0

Related Questions