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

sketch the graph of each line. 2x-5y=25
If you visit the Senate chamber during a session on an average day, you're most likely to find the session presided over by A: a president pro term B: the Vice
The train travels 120 miles in 2 hours. How far will the train travel in 4 hours?
the jazz band has m members to raise money for a tour each member sold raffle tickets write the expression to show the number of raffle tickets sold your a
what must be true about any point that lies on the x axis
How are elements identified in terms of their atoms?
A Cylindrical container of salt is 6 inches and its base has a radius of 2 inches how much paper is neededto completly cover the container
what is 2 7/8 plus 2 3/8 ?
Are the various branches of science separate or do they overlap
The train travels 120 miles in 2 hours. How far will the train travel in 4 hours?