[Tutor] How to skip to next line in for loop
Alan Gauld
alan.gauld at btinternet.com
Fri May 2 01:51:19 CEST 2008
"bob gailer" <bgailer at gmail.com> wrote
>> if line == "3":
>
> Assuming you adopt my approach, then each line will be a digit
> followed by \n (newline). So no line will == "3". Instead use:
>
> if line[:-1] == "3":
or
if line.rstrip() == "3"
or even
if line.startswith("3"):
personally I prefer rstrip() over the -1 slice because it catches
more potential junk.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list