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

  • Home
  • SEARCH
  • 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 447453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:34:19+00:00 2026-05-12T21:34:19+00:00

If I write for i in range(5): print i Then it gives 0, 1,

  • 0

If I write

for i in range(5):
      print i

Then it gives 0, 1, 2, 3, 4
Does that mean Python assigned 0, 1, 2, 3, 4 to i at the same time?
However if I wrote:

for i in range(5):
      a=i+1

Then I call a, it only gives 5
But if I add ”print a” it gives 1, 2, 3, 4, 5
So my question is what is the difference here?
Is i a string or a list or something else?

Or maybe can anyone help me to sort out:

for l in range(5):
    #vs,fs,rs are all m*n matrixs,got initial values in,i.e vs[0],fs[0],rs[0] are known
    #want use this foor loop to update them
    vs[l+1]=vs[l]+fs[l]
    fs[l+1]=((rs[l]-re[l])
    rs[l+1]=rs[l]+vs[l]
#then this code gives vs,fs,rs

If I run this kind of code, then I will get the answer only when l=5
How can I make them start looping?

i.e l=0 got values for vs[1],fs[1],rs[1],
then l=1 got values for vs[2],rs[2],fs[2]……and so on.
But python gives different arrays of fs,vs,rs, correspond to different value of l

How can I make them one piece?

  • 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-05-12T21:34:19+00:00Added an answer on May 12, 2026 at 9:34 pm

    A “for loop” in most, if not all, programming languages is a mechanism to run a piece of code more than once.

    This code:

    for i in range(5):
        print i
    

    can be thought of working like this:

    i = 0
    print i
    i = 1
    print i
    i = 2
    print i
    i = 3
    print i
    i = 4
    print i
    

    So you see, what happens is not that i gets the value 0, 1, 2, 3, 4 at the same time, but rather sequentially.

    I assume that when you say “call a, it gives only 5”, you mean like this:

    for i in range(5):
        a=i+1
    print a
    

    this will print the last value that a was given. Every time the loop iterates, the statement a=i+1 will overwrite the last value a had with the new value.

    Code basically runs sequentially, from top to bottom, and a for loop is a way to make the code go back and something again, with a different value for one of the variables.

    I hope this answered your question.

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

Sidebar

Related Questions

If this is my subprocess: import time, sys for i in range(200): sys.stdout.write( 'reading
Please write a list of tasks that a copy constructor and assignment operator need
I write a large static method that takes a generic as a parameter argument.
I'm trying (yet again) to get better at programming, this time in python, and
I am trying to write a simple bash script that is listening on a
i need a quick hint regarding the following exercise question: Write a program that
[Python 3.1] Edit: mistake in the original code. I need to print a table.
Write a class ListNode which has the following properties: int value; ListNode *next; Provide
You write a function and, looking at the resulting assembly, you see it can
I write my app in VS 2008 and so use all the fanciful stuffs

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.