Okay. Let me see if I can help you with the concept of âzero indexingâ. Indexing is another fundamental concept that is key to Python coding and, by default, an index starts at zero, not one.
Consider this string of characters: python
The index for that string is thus:
0 | 1 | 2 | 3 | 4 | 5
p | y | t | h | o | n
So, if we have this simple code:
name = 'python'
print(name[1])
⌠we will see the letter y
displayed. If we wanted the first three letter, weâd use print(name[0:3])
and weâd see pyt
displayed. Notice here that the forth letter is h
and is at index position 3
. So, that pyt
âsub-stringâ is three characters in length and is a so-called âsliceâ of the name
object to which the string python
has been assigned and is constructed from index position 0
up to, but not including, index position 3
.
What we could now do, is to assign our python
string to object A
and two integer values to two more objects (B
and C
) and use those, like this:
A = 'python'
B = 0
C = 3
print(A[B:C])
⌠which would display the same sub-string: pyt
This satisfies the Problem Constraints, namely that our âstringâ, (which is represented as |A|
) is greater than or equal to 1 character and is less than or equal to 100 characters, B
is greater than or equal to 0
and C
less than the length of the âstringâ. If you wanted your code to display the length of your âstringâ, you can use a builtin function called len()
.
You can see that itâs a function, because of the parentheses, and you can combine functions like this: print(len(A))
. Here, the len()
function will return the length of the string of characters that have been assigned to the A
object, and pass that value to the print()
function, which will in turn display said value.
So, given this information, you should now be able to apply what youâve learned to the task at hand.