PDA

View Full Version : help with .lstrip() to remove whitespace



pluckypigeon
January 30th, 2009, 07:37 PM
for i in range(111111,999999):
print "test", i



output > test 111111
..and so on


I'm trying to remove the whitespace between test and the numbers.

I tried implementing ".lstrip" but I can't work out where to put it.

Any help would be really appreciated

Thanks in advance.

pluckypigeon
January 30th, 2009, 07:44 PM
Nevermind

I forgot to convert the integer




for i in range(111111,999999):
print "test" + str(i) .lstrip()

rajeev1204
January 30th, 2009, 07:52 PM
There is no need to use lstrip here.

The + operator will remove the whitespace for you and concatenate the strings

pluckypigeon
January 30th, 2009, 07:55 PM
There is no need to use lstrip here.

The + operator will remove the whitespace for you and concatenate the strings

:redface: I was just coming back to change that before anyone saw...

thanks anywho:)

snova
January 30th, 2009, 08:34 PM
I'm trying to remove the whitespace between test and the numbers.

I tried implementing ".lstrip" but I can't work out where to put it.

It wouldn't matter where you put it. The print statement automatically puts a space in between each of its arguments. To get around it you'd have to use string concatentation, as you've already figured out.

fiddler616
January 30th, 2009, 11:24 PM
The print statement automatically puts a space in between each of its arguments. To get around it you'd have to use string concatentation, as you've already figured out.
Suppose I wanted whitespace, would it be with commas instead of +s?

rajeev1204
January 31st, 2009, 10:42 AM
Suppose I wanted whitespace, would it be with commas instead of +s?


Well,a comma is always required to print multiple strings.But if you need an extra whitespace,put it in like so ...


print "hello ","forums"

This will print extra whitespaces after hello as you can see from code.

WW
January 31st, 2009, 01:25 PM
Nevermind

I forgot to convert the integer




for i in range(111111,999999):
print "test" + str(i) .lstrip()


You could also use a format string:



for i in range(111111,999999):
print "test%d" % i

rajeev1204
February 1st, 2009, 11:50 AM
You could also use a format string:



for i in range(111111,999999):
print "test%d" % i



Ya this is the best way.Thanks for this.