Ask Question
17 December, 17:59

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

+1
Answers (1)
  1. 17 December, 19:26
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers