Light Mode
Dark Mode
string slicing question

I am a total noob with Python and seem to be doing something wrong or misunderstand string slicing. Here is the code I wrote to validate how things work:

time1 = '12:30'
print(time1[0])
print(time1[1])
print(time1[2])
print(time1[0:2])

Here is the output that I get:

1 <cr> 2 <cr> : <cr> 12 <cr>

Shouldn't "print(time1[0:2])" print out the first 3 characters (12:) of the string time1? What am I missing?

Thanks, Greg

Created: Aug. 15, 2019, 10:20 p.m.
Updated: Aug. 16, 2019, 11:25 a.m.
0
14
User avatar
gregcooper5