Sunday, May 29, 2011

Python exercise: Slicing Strings

exercise:
HelloString = "Hello Python!"
print(HelloString)

print("Python exercise: Slicing Strings")
print (HelloString[2:10]) #from index 2 to 10-1
print (HelloString[2:]) #from index 2 to end
print (HelloString[:10]) #from begin to 10-1
print (HelloString[::3]) #every 3 characters
print (HelloString[::-1]) #every characters in reverse order


output:
Python exercise: Slicing Strings