l = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
for x in l:
print(S[::2], [1::2])
what does the print statement mean in this program
l = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
for x in l:
print(S[::2], [1::2])
what does the print statement mean in this program
A double colon ::x
means to skip by x
. In this case it is skipping by 2
.
So if you have l=[ 'a','b','c','d','e','f','g']
and you want to find l[::2]
, then starting at 'a'
, you move to 'c'
, and so on.
Now, if you have a number before the colons, such as x::y
. This means to start at index x
and skip by y
.