Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8335497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:41:41+00:00 2026-06-09T03:41:41+00:00

the resource i am using to learn python has you perform modules within its

  • 0

the resource i am using to learn python has you perform modules within its own website. i think it was originally designed for students of this particular university so that is why i have tagged this with homework, even though it is not.

anyway:

they had me perform this task:

Define a function prod(L) which returns the product of the elements in a list L.

i got this function to work using this code:

def prod(L):
   i = 0
   answer = 1
   x = len(L)
   while i < x:
    answer = answer * L[i]
    i = i + 1
    if i == x:
         return answer

the very next module talks very briefly about For-In loops. and they pose the question:

Define the function prod(L) as before, but this time using the new kind of loop.

i have tried looking through other resources to understand how exactly to use this but i am not following anything. can anybody explain, preferably in plain english, how a for-in loop works?

for reference: here is EVERYTHING that they talked about regarding the for-in loop

Looping through lists It is very common (like in the previous
exercise) to loop through every value in a list. Python allows a
shortcut to perform this type of an operation, usually called a “for
all” loop or a “for each” loop. Specifically, when L is a list, this
code

for x in L: «loop body block»

does the following: first x is set to
the first value in L and the body is executed; then x is set to the
second value in L and the body is executed; this is continued for all
items in L.

i just cant fully wrap my head around this. im not looking for answers as i am doing this for knowledge growth – but i feel like im falling behind on this ):

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:41:42+00:00Added an answer on June 9, 2026 at 3:41 am

    In the explanation given, L is an iterable. This can be a sequence (e.g. list, tuple, string) or a generator (e.g. xrange()). Each element of the iterable is bound to the name x in turn, and the loop body is executed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python noob trying to learn Pylons. I'm using the QuickWiki tutorial ( http://pylonshq.com/docs/en/1.0/tutorials/quickwiki_tutorial/ )
Whenever I specify a resource using the Spring Data Hadoop namespace, by application throws
i have seen people localize their form using resource. put text data in resource
I'm binding my viewmodel and view using resource dictionary as follows <DataTemplate DataType={x:Type viewmodels:MyViewModel}>
I have successfully implemented slider to my Cocos2D project using this resource . The
In C++, when using the Resource Acquisition is Initialization (RAII) pattern, are there any
I using the Rails resource_controller plugin. I have a ReleasesController, which is nested within
Using a restful resource in Rails, I would like to be able to insert
I am using YepNope as a resource loader, but I am now having to
I am using simulated annealing to solve an NP-complete resource scheduling problem. For each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.