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

In-sink garbage disposal units in the home is sometimes described as "on-site disposal". is this phrase accurate?
What is the diffrence compare and contrast?
catalysis increase the rate of reaction by
The senator wrote a letter to carol and Expressing his thanks Which pronoun correctly completes the sentence
Muslim geographers were able to do what with an astrolabe
1.if f(x)=-4x^2+15, then f(-3)= 2.if(x)=3x-2, find f(8)-f(-5)
Can someone help me with these?
In "The Black Cat," the narrator begins the story by speaking directly to the reader. The narrator continues this practice periodically throughout the story. H
Which set of lines in this excerpt from Walt Whitman's "When Lilacs Last in the Dooryard Bloom'd" is part of the lament stage of an elegy? When lilacs last in t
Each square on the periodic table includes lots of information about ?