# File String01.py
# Rev 2/4/00
# Copyright 2000, R. G. Baldwin
# Illustrates indexing and 
# slicing strings
#
#-------------------------------

aStr = "This is a string"
print aStr[0] #print T
print aStr[3] #print s
print aStr[0:4] #print This
print aStr[10:16] #print string
print aStr[:4] #print This
print aStr[10:] #print string

#print the entire string
print aStr[:5] + aStr[5:]
print aStr[:100]

#print an empty string
print "Empty: " + aStr[16:100]

#count from the right
print aStr[-5:-2] #print tri

#get the length of the string
print len(aStr)

Figure 10