Sunday, May 29, 2011

Python exercise: get character in string using negative indexing

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

StringLen = len(HelloString)
print("String Length: " + str(StringLen))

print("Print in normal order")
for i in range(0, StringLen):
print(HelloString[i])

print("Print in reverse order, negative indexing")
for i in range(1, StringLen+1):
print(HelloString[-i])



output:
Python exercise: get character in string using negative indexing