What is the difference between __getitem__ and __iter__? #31
Answered
by
lukasmiller3
lukasmiller1
asked this question in
Q&A
-
|
What is the difference between getitem and iter? |
Beta Was this translation helpful? Give feedback.
Answered by
lukasmiller3
Jan 22, 2026
Replies: 1 comment
-
|
A:getitem enables indexing (obj[i]) and is used by iteration if iter is not defined. iter explicitly defines iteration behavior and is preferred. If both exist, iter takes precedence. iter is more efficient and provides better iteration control. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
lukasmiller1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A:getitem enables indexing (obj[i]) and is used by iteration if iter is not defined. iter explicitly defines iteration behavior and is preferred. If both exist, iter takes precedence. iter is more efficient and provides better iteration control.