Sep-30-2018, 05:05 PM
I'm taking an intro Python course online.
For the code --> name="Michael Jackson" I can see why for name[0:5:2] the output is "Mca." 'M' is indexed as Zero and the 'e' is indexed as 5. So every 2nd letter is Mca, with the 'e' being the 5th character. So the 'e' is not counted, being it is an odd number.
Can someone explain why name[0:4:2] the output is not "Mca" The output I get is "Mc" It would seem that since the fourth character is 'a', if counting 'M' as ZERO, the 'a' should be part of the every 2nd character from 'M' until 'a'
In other words, why does name[0:5:2] and name[0:4:2] not both yield 'Mca'?
For the code --> name="Michael Jackson" I can see why for name[0:5:2] the output is "Mca." 'M' is indexed as Zero and the 'e' is indexed as 5. So every 2nd letter is Mca, with the 'e' being the 5th character. So the 'e' is not counted, being it is an odd number.
Can someone explain why name[0:4:2] the output is not "Mca" The output I get is "Mc" It would seem that since the fourth character is 'a', if counting 'M' as ZERO, the 'a' should be part of the every 2nd character from 'M' until 'a'
In other words, why does name[0:5:2] and name[0:4:2] not both yield 'Mca'?