Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41378

Re: [Python 2.7.3] What's the difference between these two uses of "for"?

Date 2013-03-17 20:24 -0500
From Andrew Berg <bahamutzero8825@gmail.com>
Subject Re: [Python 2.7.3] What's the difference between these two uses of "for"?
References <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3402.1363569881.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 2013.03.17 19:58, Yves S. Garret wrote:
> N00b question.  But here is the code:
> 
> http://bin.cakephp.org/view/709201806
> 
> In the first example, the first for-loop is run and then the list is assigned to the tricky variable.  But, what 
> happens in the second example?  Does the loop after "in" get run only once or multiple number of times?
> 
In the first example, sorted() returns a list, which is assigned to the
name tricky (Python doesn't have variables - names simply point to
objects in memory), and then the for loop iterates over tricky, which
points to a list. In the second example, the for loop iterates over the
list that sorted() returns. The only difference between the two is that
the list that sorted() returns is assigned to a name in the first example.

-- 
CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[Python 2.7.3] What's the difference between these two uses of "for"? "Yves S. Garret" <yoursurrogategod@gmail.com> - 2013-03-17 17:58 -0700
  Re: [Python 2.7.3] What's the difference between these two uses of "for"? Andrew Berg <bahamutzero8825@gmail.com> - 2013-03-17 20:24 -0500
  Re: [Python 2.7.3] What's the difference between these two uses of "for"? Gary Herron <gary.herron@islandtraining.com> - 2013-03-17 18:18 -0700
    Re: [Python 2.7.3] What's the difference between these two uses of "for"? "Yves S. Garret" <yoursurrogategod@gmail.com> - 2013-03-17 18:59 -0700
    Re: [Python 2.7.3] What's the difference between these two uses of "for"? "Yves S. Garret" <yoursurrogategod@gmail.com> - 2013-03-17 18:59 -0700
      Re: [Python 2.7.3] What's the difference between these two uses of "for"? "Yves S. Garret" <yoursurrogategod@gmail.com> - 2013-03-17 19:14 -0700
        Re: [Python 2.7.3] What's the difference between these two uses of "for"? Dave Angel <davea@davea.name> - 2013-03-18 07:38 -0400
      Re: [Python 2.7.3] What's the difference between these two uses of "for"? "Yves S. Garret" <yoursurrogategod@gmail.com> - 2013-03-17 19:14 -0700
        Re: [Python 2.7.3] What's the difference between these two uses of "for"? Roy Smith <roy@panix.com> - 2013-03-17 22:33 -0400
          Re: What's the difference between these two uses of "for"? alex23 <wuwei23@gmail.com> - 2013-03-18 18:08 -0700
        Re: [Python 2.7.3] What's the difference between these two uses of "for"? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-18 02:44 +0000
          Re: [Python 2.7.3] What's the difference between these two uses of "for"? Roy Smith <roy@panix.com> - 2013-03-17 22:51 -0400
  Re: [Python 2.7.3] What's the difference between these two uses of "for"? Roy Smith <roy@panix.com> - 2013-03-17 21:28 -0400
    Re: [Python 2.7.3] What's the difference between these two uses of "for"? "Yves S. Garret" <yoursurrogategod@gmail.com> - 2013-03-17 19:01 -0700
      Re: [Python 2.7.3] What's the difference between these two uses of "for"? Roy Smith <roy@panix.com> - 2013-03-17 22:28 -0400
  Re: [Python 2.7.3] What's the difference between these two uses of "for"? Terry Reedy <tjreedy@udel.edu> - 2013-03-18 00:37 -0400

csiph-web