String Exercises

Complete the following:
  1. Assign your first name to a variable named fullName
  2. Append (or add) a space and your last name to fullName
  3. Print out each of the characters in fullName with a loop
Answer the following questions then confirm with your neighbor:
  1. What is the index of the first letter of your first name in fullName?
  2. What is the index of the first letter of your last name in fullName?
  3. How can we determine the length of any str variable in python?
  4. What will be the result of the following python code?
    fullName[0] = 'Z'
  5. What does the following python script print out (if anything)?
    word = "stressed"
    
    startIndex = -1
    lastIndex = 0 - len(word)
    step = -1
    for charIndex in range( startIndex, lastIndex + step, step):
        # print the character in word specified by charIndex (and don't add a
        # newline at the end)
        print( word[ charIndex], end='')
        
    # display just a newline
    print()    
    
  6. What will be the result of each of the following statements?
    1. print( fullName[  3:5  ])
    2. print( fullName[   :5  ])
    3. print( fullName[  3:   ])
    4. print( fullName[   :   ])
    5. print( fullName[ -3:   ])
    6. print( fullName[-50:   ])
    7. print( fullName[   :-2 ])
    8. print( fullName[  3:50 ])
    9. print( fullName[  3:10:2])
    10. print( fullName[  3:10:3])