+ 2
I can't seem to find complete the code
Have been trying to learn python on solo learn but am struck on a practice question about lists. The question goes like this: write a program that takes an input string and outputs the 3rd character of the string. Then the code starts like this: text= input() #code starts here Your help will be greatly appreciated.
3 ответов
+ 7
Your Problem is Simple:
Then its code would be:
text = input() # Logic text is str (string)
print(text[2]) # 3rd Char of the string (text)
Remember that Python arrays/lists always start with 0 so 2 would be the third value.
And Basically a String is a List of Characters
Always starting at 0 and going wherever you want
Ex:
text = "I am trying hard"
print(text[0]) # = I
print(text[1]) # = (blank space)
print(text[2]) # = a
print(text[3]) # = m
print(text[4]) # = (blank space)
print(text[5]) # = t
...
+ 4
you can access string characters using index (index start from 0)
print(text[2]) #will output the 3rd char
+ 1
Sequence 0,1,2,3,4,5,6,7,8,9.,