testString = '<a herf="http://www.python.org">python web site </a>'
print testString[0:1]
print testString[9:30]
print testString[32:-4]
print testString[-3:0]
print testString[-3:1]
print testString[-3:]
print testString[:-3]
print testString[:]
#step > 1
print testString[0:10:1]
print testString[0:10:2]
print testString[::4]
print testString[:10:2]
print testString[10:0:-2]
执行结果:
<
http://www.python.orgpython web site
/a>
<a herf="http://www.python.org">python web site <
<a herf="http://www.python.org">python web site </a>
<a herf="h
< ef"
<e"pwporpoei<
< ef"
t"fe