Basic String Manipulations

word = 'banana talks'

for i in word:  #Here the i is the letters in the string word
      print 'Character from string:',i

for h in range(len(word)):   #Here the h is index created by range function with value created by length
      print 'Index:',h,'charater:' ,word[h]

n1 = word.upper()

print 'String in the upper case:', n1

n2 = word.lower()

print 'String in the lower case:', n2

print 'Display a part of string :',word[1:5] # It display string from index 1 to 4

print 'Display a part of string :',word[4:8] # It display string from index 4 to 7

No comments: