I have 3 years of PHP experience and currently trying to catch up with Python on sololearn. The first question in Intermediate Python that checks my Python knowledge goes like this:
n = [2, 4, 6, 8]
res = 1
for x in n[1:3]:
res *= x
I am confused why the result is 24, my logic is that n[1:3]
means n[1] * n[2] * n[3]
so 4 * 6 * 8
.
I searched on google about for loops in Python but i only find stuff about the range()
function, couldn't find an explanation for the :
operator