Ask Question

Given a string variable named "myString" of length 5, how could you access the first character and last character using a numeric index?

+4
Answers (1)
  1. 16 June, 22:37
    0
    The first index myString[0]

    The last index myString[4]

    Explanation:

    Indexing starts at "0". so the first character in a string will be at index "0" and the last character will be at index "-1". But since we were given the length of this string to be 5, we know that the index of the last character will be "4".

    The python code bellow will print character at the first and last index:

    myString = "hello"

    print ("The First Index is "+myString[0])

    print ("The Last Index is "+myString[-1])
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Given a string variable named "myString" of length 5, how could you access the first character and last character using a numeric index? ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers