Alan Gauld wrote:
Hi Emile,
On 26/06/12 00:26, Emile van Sebille wrote:
Try using the operator that checks for equality such as
if w[0] == 'x':
This does the same thing and works even when w is an empty string.
Umm, so does startswith()? Can you clarify what you mean by the last
sentence?
I think you've messed up your quoting. It was Mike Nickey, not Emile, who
suggested using w[0] == 'x'.
As Emile said, startswith is better because it works when w is an empty
string, while the w[0]=='x' test fails:
py> w = ''
py> w.startswith('x')
False
py> w[0] == 'x'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: string index out of range
--
Steven
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor