What is the output of the following python code snippet

0 votes
for i in range(0, 10, 2):
    if (i % 5 == 0):
        print(i)

Need Explanation of the above code.


Feb 9 in Python by Dev
• 6,000 points
18 views

1 answer to this question.

0 votes

for i in range(0, 10, 2):
    if (i % 5 == 0):
        print(i)

Output:

0

Since all are even numbers (0,2,4,6,8) and we iterate through even numbers, when these numbers are divided by 5 the  remainder will never be 0.The last element will not be included here i.e. 10
Hence, the only result we get is 0 in this case.

Hope this helps!

answered Feb 9 by Nandini
• 5,480 points

Related Questions In Python

0 votes
1 answer

What is the purpose of ​#!/usr/bin/python​on the first line in the above code?

Hey, @Roshni, By specifying #!/usr/bin/python you specify exactly ...READ MORE

answered Jun 23, 2020 in Python by Gitika
• 65,850 points
3,641 views
+2 votes
3 answers

what is the practical use of polymorphism in Python?

Polymorphism is the ability to present the ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,440 points
3,090 views
0 votes
2 answers

What is the use of Python language?

python is general purpose programming language.it very ...READ MORE

answered Mar 15, 2019 in Python by rajesh kumar
231 views
0 votes
1 answer

What is the use of raw_input function in Python?

raw_input fuction is no longer available in ...READ MORE

answered May 2, 2018 in Python by aayushi
• 750 points
464 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 58,060 points
1,035 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 14, 2018 in Python by Priyaj
• 58,060 points
304 views
0 votes
1 answer

“stub” __objclass__ in a Python class how to implement it?

You want to avoid interfering with this ...READ MORE

answered Sep 27, 2018 in Python by Priyaj
• 58,060 points
662 views
+1 vote
1 answer

How is raw_input() and input() in python3.x?

raw_input() was renamed to input() so now input() returns the exact string ...READ MORE

answered Oct 30, 2018 in Python by Priyaj
• 58,060 points
366 views
0 votes
1 answer

What is the use of "assert" in Python?

The statement assert exists in almost every programming ...READ MORE

answered Feb 7 in Python by Nandini
• 5,480 points
23 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP