Hearts8812 Hearts8812
  • 22-01-2020
  • Computers and Technology
contestada

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

Respuesta :

ijeggs
ijeggs ijeggs
  • 22-01-2020

Answer:

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])

Answer Link

Otras preguntas

How do I solve this complex multi-step equation 2x + (-2 )= 10x - 4 ?
A number (x) increased by 6 and then the sum is doubled
Which of the following statements does NOT contribute to the evidence in support of evolution? (A) Sequences of fossils have been found that show a gradual seri
A musical instrument depreciates by 20% of its value each year. What is the value, after 2 years, of a piano purchased new for $1200?
what is the 23rd term from these sequences   5,6,7,8,9
find the midpoint of the line segment joining the points P1 and P2P1=(3,-4); P2=(5,4)
why did people hate the roman empire
use the order of operations to evaluate each expression. 4x4+3
A MILKMAN SOLD TWO OF HIS BUFFALOES FOR RS.20,000. EACH ON ONE HE MADE A GAIN OF 5% AND ON THE OTHER A LOSS OF 10%. FIND HIS OVERALL GAIN OR LOSS.
find y for x= 1,2,3,and 4y=2x     y=3x+1   y=x-5    y=-5x+6