+ 1
word filter
words = ["cat", "car", "code", "home", "learn", "fun", "job", "love", "friend", "zoo", "enjoy", "happiness", "family", "goal", "desire"] #your code goes here x=input() for i in words: if x in i: print(i) I don´t understand for what i is standing for. The code is not working if I use any other letter. Could someone please explain it to me. Thanks in advance.
7 Antworten
+ 10
Denis Durban
the variables in *python for loops* like "i", "j" or whatever the name is, are *not* counters.
they are so called loop variables. iterating through a list or an other iterable takes one item at a time and assigns it to the loop variable. so we are able to take that item and process it.
+ 5
'i' is a temporary variable to hold list items in iterations.
You can use any name for variable there. It works.
For better understand, share your code which is not working, by saving in playground.
for i in words: print(i)
for j in words: print(j)
for k in words : print(k)
These 3 statements works same.. Having different temp variable names..
+ 2
Jayakrishna 🇮🇳 ah ok got it. Thank you both.
0
Mirielle I mean there is the letter i in this code. Example: for i in words. If I change the letter i with any other letter the code does not work anymore. Does i have a special meaning I am missing?
0
Mirielle thats exactly what happend. I just started yesterday with coding, I am making so many little mistakes.
0
Denis Durban
Dear,in for loops,we need a counter to count ,this counter is usually named as I,j,k,...
These letters are usable In nested for loops those we need two or more counters
0
Hlw