简体   繁体   中英

How to rid of spaces in line, python

there are lines and in line there are spaces, so i want to get rid of spaces to left just strings.

spaces like '', '', '' so which code should i use to delete spaces?

Thnks

st = " with, or,  without ,  spaces            ";
st = st.replace(" ","")
print(st)
with,or,without,spaces

you could use

sys.stdout.write("something")
sys.stdout.write("without")
sys.stdout.write("spaces")

instead of

print "something", "without", "spaces"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM