Ask Question
15 March, 20:40

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

+5
Answers (1)
  1. 15 March, 20:56
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers