0

When I use the code in python 2.7.5

for i in [1,2]: print 'distance',':400@CA',':',i,'@CA' 

I got the following

distance :400@CA : 1 @CA distance :400@CA : 2 @CA 

I want to remove the space (eg., among :,1,@CA) so that the output will be like

distance :400@CA :1@CA distance :400@CA :2@CA 

I also tried using sep='' or end='' but still they don't work. Any suggestion will be appreciated.

4 Answers 4

2

I'd use the string formatting operator %:

for i in [1,2]: print 'distance :400@CA :%d@CA' % i 

This gives you quite a lot of control over how things are laid out.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use %d operator:

for i in [1,2]: print 'distance',':400@CA',':','%d@CA' % i 

Or you can use join:

for i in [1,2]: print 'distance'+':400@CA:'.join(i,'@CA') 

With reference to:How to print a string of variables without spaces in Python (minimal coding!)

Hope this helps...

Comments

0
 for i in [1,2]: print 'distance',':400@CA',':'+str(i)+'@CA' Output: distance :400@CA :1@CA distance :400@CA :2@CA 

Using ,(comma) will add space while printing. Better concatenate using +

Comments

0

Use the sep tag in print

from __future__ import print_function print('distance',':400@CA',':',i,'@CA', sep = '') 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.