[Tutor] Tutor Digest, Vol 100, Issue 58

Alan Gauld alan.gauld at btinternet.com
Tue Jun 26 02:07:31 CEST 2012


On 25/06/12 23:12, Mike Nickey wrote:

> I did the same exercise so maybe I can assist here. From what I see, the line...
> if w.startswith('x'): seems to be ineffective.

If that's true you have a seriously broken version of Python!
startswith() is a better idiom because it conveys the intent much more 
clearly. And it should work just fine!

 >>> 'xray'.startswith('x')
True
 >>> 'xray'.startswith('y')
False
 >>>

The only real downside is a few extra characters typing!

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/





More information about the Tutor mailing list