Hi guys. I am struggling with understanding this code. How is the i % 2 ==0 print out even indexs? I feel I am struggling with what I is for. I would appreciate any help, i just want to understand and learn. Thank you!
for i in range(len(word)):
if i % 2 == 0:
Because the index is,
i, and it has even parity (divisible by 2).
Does your output look like this?
Yes my output is
It prints out all even indexes. I am confused on why it is doing that? I think my confusion is coming around the i and how it produces only even indexes? Thank you!
if i % 2 == 0 means if i divided by 2 has no remainders… which is the same as saying if i is even
it sounds like youre just confused on how % works
Yea I understand it now. Thanks!
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.