how does list x operates if(x % i) == 0












-1















so i'm learning coding for a few weeks now and just got over something that i really cant explain by my self.



for word in ['ox', 'cat', 'lion', 'tiger', 'bobcat']:
for i in range(2, 7):
letters = len(word)
if (letters % i) == 0:
print(i, word)


when we define variable letter = len(word) this literally means letter = 5 right? If it do so and we go over to the if condition it says: (letter % i) == 0 for me what this means is when we start the second for-loop (5 % 2) == 0 (1) == 0 I know thats actually not right cause word in that case is a variable and not a list. But if i set letter so the position of each word like ox= len(0) that doesn't makes sense to me either thats how i am thinking about this. unfortunately shell is has given me this



    2 ox
3 cat
2 lion
4 lion
5 tiger
2 bobcat
3 bobcat
6 bobcat


I really can't figure out how this loop works but i really want to understand. I'ver tried several things but nothing worked in a sense of logic.



I hope you can help a beginner out :) P.S. sorry for my bad english haha










share|improve this question

























  • Indentations matter in Python. please fix

    – Vineeth Sai
    Nov 22 '18 at 6:04











  • % is the modulo operator. Just search for 'python modulo operator'

    – Red Cricket
    Nov 22 '18 at 6:08











  • @RedCricket He seems to understand that, he knows that (5 % 2) is 1.

    – Barmar
    Nov 22 '18 at 6:10






  • 1





    I don't understand the question. word is a variable whose value is a string. So len(word) is the length of the string.

    – Barmar
    Nov 22 '18 at 6:11











  • Try for word in ['ox', 'cat', 'lion', 'tiger', 'bobcat']: print(word) and you'll see what word is (hint: it's not the list).

    – Matthias
    Nov 22 '18 at 9:12
















-1















so i'm learning coding for a few weeks now and just got over something that i really cant explain by my self.



for word in ['ox', 'cat', 'lion', 'tiger', 'bobcat']:
for i in range(2, 7):
letters = len(word)
if (letters % i) == 0:
print(i, word)


when we define variable letter = len(word) this literally means letter = 5 right? If it do so and we go over to the if condition it says: (letter % i) == 0 for me what this means is when we start the second for-loop (5 % 2) == 0 (1) == 0 I know thats actually not right cause word in that case is a variable and not a list. But if i set letter so the position of each word like ox= len(0) that doesn't makes sense to me either thats how i am thinking about this. unfortunately shell is has given me this



    2 ox
3 cat
2 lion
4 lion
5 tiger
2 bobcat
3 bobcat
6 bobcat


I really can't figure out how this loop works but i really want to understand. I'ver tried several things but nothing worked in a sense of logic.



I hope you can help a beginner out :) P.S. sorry for my bad english haha










share|improve this question

























  • Indentations matter in Python. please fix

    – Vineeth Sai
    Nov 22 '18 at 6:04











  • % is the modulo operator. Just search for 'python modulo operator'

    – Red Cricket
    Nov 22 '18 at 6:08











  • @RedCricket He seems to understand that, he knows that (5 % 2) is 1.

    – Barmar
    Nov 22 '18 at 6:10






  • 1





    I don't understand the question. word is a variable whose value is a string. So len(word) is the length of the string.

    – Barmar
    Nov 22 '18 at 6:11











  • Try for word in ['ox', 'cat', 'lion', 'tiger', 'bobcat']: print(word) and you'll see what word is (hint: it's not the list).

    – Matthias
    Nov 22 '18 at 9:12














-1












-1








-1








so i'm learning coding for a few weeks now and just got over something that i really cant explain by my self.



for word in ['ox', 'cat', 'lion', 'tiger', 'bobcat']:
for i in range(2, 7):
letters = len(word)
if (letters % i) == 0:
print(i, word)


when we define variable letter = len(word) this literally means letter = 5 right? If it do so and we go over to the if condition it says: (letter % i) == 0 for me what this means is when we start the second for-loop (5 % 2) == 0 (1) == 0 I know thats actually not right cause word in that case is a variable and not a list. But if i set letter so the position of each word like ox= len(0) that doesn't makes sense to me either thats how i am thinking about this. unfortunately shell is has given me this



    2 ox
3 cat
2 lion
4 lion
5 tiger
2 bobcat
3 bobcat
6 bobcat


I really can't figure out how this loop works but i really want to understand. I'ver tried several things but nothing worked in a sense of logic.



I hope you can help a beginner out :) P.S. sorry for my bad english haha










share|improve this question
















so i'm learning coding for a few weeks now and just got over something that i really cant explain by my self.



for word in ['ox', 'cat', 'lion', 'tiger', 'bobcat']:
for i in range(2, 7):
letters = len(word)
if (letters % i) == 0:
print(i, word)


when we define variable letter = len(word) this literally means letter = 5 right? If it do so and we go over to the if condition it says: (letter % i) == 0 for me what this means is when we start the second for-loop (5 % 2) == 0 (1) == 0 I know thats actually not right cause word in that case is a variable and not a list. But if i set letter so the position of each word like ox= len(0) that doesn't makes sense to me either thats how i am thinking about this. unfortunately shell is has given me this



    2 ox
3 cat
2 lion
4 lion
5 tiger
2 bobcat
3 bobcat
6 bobcat


I really can't figure out how this loop works but i really want to understand. I'ver tried several things but nothing worked in a sense of logic.



I hope you can help a beginner out :) P.S. sorry for my bad english haha







python






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 6:08









Barmar

434k36260363




434k36260363










asked Nov 22 '18 at 6:03









SiddharthaSiddhartha

1




1













  • Indentations matter in Python. please fix

    – Vineeth Sai
    Nov 22 '18 at 6:04











  • % is the modulo operator. Just search for 'python modulo operator'

    – Red Cricket
    Nov 22 '18 at 6:08











  • @RedCricket He seems to understand that, he knows that (5 % 2) is 1.

    – Barmar
    Nov 22 '18 at 6:10






  • 1





    I don't understand the question. word is a variable whose value is a string. So len(word) is the length of the string.

    – Barmar
    Nov 22 '18 at 6:11











  • Try for word in ['ox', 'cat', 'lion', 'tiger', 'bobcat']: print(word) and you'll see what word is (hint: it's not the list).

    – Matthias
    Nov 22 '18 at 9:12



















  • Indentations matter in Python. please fix

    – Vineeth Sai
    Nov 22 '18 at 6:04











  • % is the modulo operator. Just search for 'python modulo operator'

    – Red Cricket
    Nov 22 '18 at 6:08











  • @RedCricket He seems to understand that, he knows that (5 % 2) is 1.

    – Barmar
    Nov 22 '18 at 6:10






  • 1





    I don't understand the question. word is a variable whose value is a string. So len(word) is the length of the string.

    – Barmar
    Nov 22 '18 at 6:11











  • Try for word in ['ox', 'cat', 'lion', 'tiger', 'bobcat']: print(word) and you'll see what word is (hint: it's not the list).

    – Matthias
    Nov 22 '18 at 9:12

















Indentations matter in Python. please fix

– Vineeth Sai
Nov 22 '18 at 6:04





Indentations matter in Python. please fix

– Vineeth Sai
Nov 22 '18 at 6:04













% is the modulo operator. Just search for 'python modulo operator'

– Red Cricket
Nov 22 '18 at 6:08





% is the modulo operator. Just search for 'python modulo operator'

– Red Cricket
Nov 22 '18 at 6:08













@RedCricket He seems to understand that, he knows that (5 % 2) is 1.

– Barmar
Nov 22 '18 at 6:10





@RedCricket He seems to understand that, he knows that (5 % 2) is 1.

– Barmar
Nov 22 '18 at 6:10




1




1





I don't understand the question. word is a variable whose value is a string. So len(word) is the length of the string.

– Barmar
Nov 22 '18 at 6:11





I don't understand the question. word is a variable whose value is a string. So len(word) is the length of the string.

– Barmar
Nov 22 '18 at 6:11













Try for word in ['ox', 'cat', 'lion', 'tiger', 'bobcat']: print(word) and you'll see what word is (hint: it's not the list).

– Matthias
Nov 22 '18 at 9:12





Try for word in ['ox', 'cat', 'lion', 'tiger', 'bobcat']: print(word) and you'll see what word is (hint: it's not the list).

– Matthias
Nov 22 '18 at 9:12












1 Answer
1






active

oldest

votes


















0














To start, len(word) is not necessarily 5, it's the length of the current word. So, first it is 2, then 3, then 4, then 5, then 6. You've made it so the program only prints when (letters % i) == 0. For the words of length 2, that only happens (in your range of 2 to 7) when i == 2. For words of length 3, this happens when i == 3. However, for words of length 4, this happens when i == 2 and also i == 4. You can see this by looking at the values of i printed out.



Does that make sense? If you'd like me to clarify anything, just leave a comment :)






share|improve this answer
























  • Alright, thanks. Really needed that clarification. Thank you :) 🤙

    – Siddhartha
    Nov 22 '18 at 12:47











  • No problem. Welcome to Stack Overflow! If this resolved your question, you can mark the answer as accepted if you like :)

    – Unsolved Cypher
    Nov 23 '18 at 4:50












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424759%2fhow-does-list-x-operates-ifx-i-0%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














To start, len(word) is not necessarily 5, it's the length of the current word. So, first it is 2, then 3, then 4, then 5, then 6. You've made it so the program only prints when (letters % i) == 0. For the words of length 2, that only happens (in your range of 2 to 7) when i == 2. For words of length 3, this happens when i == 3. However, for words of length 4, this happens when i == 2 and also i == 4. You can see this by looking at the values of i printed out.



Does that make sense? If you'd like me to clarify anything, just leave a comment :)






share|improve this answer
























  • Alright, thanks. Really needed that clarification. Thank you :) 🤙

    – Siddhartha
    Nov 22 '18 at 12:47











  • No problem. Welcome to Stack Overflow! If this resolved your question, you can mark the answer as accepted if you like :)

    – Unsolved Cypher
    Nov 23 '18 at 4:50
















0














To start, len(word) is not necessarily 5, it's the length of the current word. So, first it is 2, then 3, then 4, then 5, then 6. You've made it so the program only prints when (letters % i) == 0. For the words of length 2, that only happens (in your range of 2 to 7) when i == 2. For words of length 3, this happens when i == 3. However, for words of length 4, this happens when i == 2 and also i == 4. You can see this by looking at the values of i printed out.



Does that make sense? If you'd like me to clarify anything, just leave a comment :)






share|improve this answer
























  • Alright, thanks. Really needed that clarification. Thank you :) 🤙

    – Siddhartha
    Nov 22 '18 at 12:47











  • No problem. Welcome to Stack Overflow! If this resolved your question, you can mark the answer as accepted if you like :)

    – Unsolved Cypher
    Nov 23 '18 at 4:50














0












0








0







To start, len(word) is not necessarily 5, it's the length of the current word. So, first it is 2, then 3, then 4, then 5, then 6. You've made it so the program only prints when (letters % i) == 0. For the words of length 2, that only happens (in your range of 2 to 7) when i == 2. For words of length 3, this happens when i == 3. However, for words of length 4, this happens when i == 2 and also i == 4. You can see this by looking at the values of i printed out.



Does that make sense? If you'd like me to clarify anything, just leave a comment :)






share|improve this answer













To start, len(word) is not necessarily 5, it's the length of the current word. So, first it is 2, then 3, then 4, then 5, then 6. You've made it so the program only prints when (letters % i) == 0. For the words of length 2, that only happens (in your range of 2 to 7) when i == 2. For words of length 3, this happens when i == 3. However, for words of length 4, this happens when i == 2 and also i == 4. You can see this by looking at the values of i printed out.



Does that make sense? If you'd like me to clarify anything, just leave a comment :)







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 6:11









Unsolved CypherUnsolved Cypher

510316




510316













  • Alright, thanks. Really needed that clarification. Thank you :) 🤙

    – Siddhartha
    Nov 22 '18 at 12:47











  • No problem. Welcome to Stack Overflow! If this resolved your question, you can mark the answer as accepted if you like :)

    – Unsolved Cypher
    Nov 23 '18 at 4:50



















  • Alright, thanks. Really needed that clarification. Thank you :) 🤙

    – Siddhartha
    Nov 22 '18 at 12:47











  • No problem. Welcome to Stack Overflow! If this resolved your question, you can mark the answer as accepted if you like :)

    – Unsolved Cypher
    Nov 23 '18 at 4:50

















Alright, thanks. Really needed that clarification. Thank you :) 🤙

– Siddhartha
Nov 22 '18 at 12:47





Alright, thanks. Really needed that clarification. Thank you :) 🤙

– Siddhartha
Nov 22 '18 at 12:47













No problem. Welcome to Stack Overflow! If this resolved your question, you can mark the answer as accepted if you like :)

– Unsolved Cypher
Nov 23 '18 at 4:50





No problem. Welcome to Stack Overflow! If this resolved your question, you can mark the answer as accepted if you like :)

– Unsolved Cypher
Nov 23 '18 at 4:50




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424759%2fhow-does-list-x-operates-ifx-i-0%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to send String Array data to Server using php in android

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Is anime1.com a legal site for watching anime?