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


Groups > comp.lang.python > #62682

Re: Variables in a loop, Newby question

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <tm@tobix.eu>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'python.': 0.02; 'tutorial': 0.03; 'variables': 0.07; 'function:': 0.09; 'subject:question': 0.10; 'python': 0.11; 'be:': 0.16; 'received:188.40': 0.16; 'received:188.40.28': 0.16; 'received :your-server.de': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'python?': 0.22; 'to:name:python-list@python.org': 0.22; 'header:User- Agent:1': 0.23; 'lets': 0.24; 'handling': 0.26; 'header:In-Reply- To:1': 0.27; "i'm": 0.30; '(on': 0.31; 'this.': 0.32; 'url:python': 0.33; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'really': 0.36; 'var': 0.36; 'url:org': 0.36; 'to:addr:python- list': 0.38; 'little': 0.38; 'short': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'url:3': 0.61; 'first': 0.61; 'email addr:gmail.com': 0.63; 'results': 0.69; 'received:178': 0.74; '10:': 0.84; 'do:': 0.91
Date Tue, 24 Dec 2013 17:24:01 +0100
From "Tobias M." <tm@tobix.eu>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130804 Thunderbird/17.0.8
MIME-Version 1.0
To "python-list@python.org" <python-list@python.org>
Subject Re: Variables in a loop, Newby question
References <9ad01eef-baf0-4018-833e-0b4dce4b9b85@googlegroups.com>
In-Reply-To <9ad01eef-baf0-4018-833e-0b4dce4b9b85@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Authenticated-Sender tm@tobix.eu
X-Virus-Scanned Clear (ClamAV 0.97.8/18280/Tue Dec 24 12:52:26 2013)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4598.1387902250.18130.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1387902250 news.xs4all.nl 2865 [2001:888:2000:d::a6]:47613
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:62682

Show key headers only | View raw


On 24.12.2013 17:07, vanommen.robert@gmail.com wrote:
> Hello, for the first time I'm trying te create a little Python program. (on a raspberri Pi)
>
> I don't understand the handling of variables in a loop with Python.
>
>
> Lets say i want something like this.
>
> x = 1
> while x <> 10
> 	var x = x
> 	x = x + 1
>
> The results must be:
>
> var1 = 1
> var2 = 2
>
> enz. until var9 = 9
>
> How do i program this in python?
You could do:

x = 1
while x < 10:
     print(x)
     x += 1

But that would be very "unpythonic".
Instead I would use a for loop and the range() function:

for x in range(1,10):
     print(x)

This is really short and readable.

I recommend reading the python tutorial to understand the basics:
http://docs.python.org/3/tutorial/

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


Thread

Variables in a loop, Newby question vanommen.robert@gmail.com - 2013-12-24 08:07 -0800
  Re: Variables in a loop, Newby question Joel Goldstick <joel.goldstick@gmail.com> - 2013-12-24 11:20 -0500
  Re: Variables in a loop, Newby question "Tobias M." <tm@tobix.eu> - 2013-12-24 17:24 +0100
  Re: Variables in a loop, Newby question Peter Otten <__peter__@web.de> - 2013-12-24 17:29 +0100
  Re: Variables in a loop, Newby question bob gailer <bgailer@gmail.com> - 2013-12-24 12:26 -0500
  Re: Variables in a loop, Newby question vanommen.robert@gmail.com - 2013-12-24 09:54 -0800
    Re: Variables in a loop, Newby question Joel Goldstick <joel.goldstick@gmail.com> - 2013-12-24 13:10 -0500
    Re: Variables in a loop, Newby question Dave Angel <davea@davea.name> - 2013-12-24 13:42 -0500
    Re: Variables in a loop, Newby question Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-25 13:35 -0500
  Re: Variables in a loop, Newby question vanommen.robert@gmail.com - 2013-12-24 10:27 -0800
    Re: Variables in a loop, Newby question Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-25 02:54 +0000
      Re: Variables in a loop, Newby question Cameron Simpson <cs@zip.com.au> - 2013-12-25 16:42 +1100
        Re: Variables in a loop, Newby question Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-25 15:27 +0000
          Re: Variables in a loop, Newby question Cameron Simpson <cs@zip.com.au> - 2013-12-26 12:01 +1100
          Re: Variables in a loop, Newby question Chris Angelico <rosuav@gmail.com> - 2013-12-26 12:35 +1100
            Re: Variables in a loop, Newby question Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-26 16:41 +1100
              Re: Variables in a loop, Newby question Dave Angel <davea@davea.name> - 2013-12-26 03:14 -0500
              Re: Variables in a loop, Newby question Chris Angelico <rosuav@gmail.com> - 2013-12-26 19:24 +1100
    Re: Variables in a loop, Newby question Peter Otten <__peter__@web.de> - 2013-12-25 15:52 +0100
    Re: Variables in a loop, Newby question Michael Torrie <torriem@gmail.com> - 2013-12-25 23:34 -0700
  Re: Variables in a loop, Newby question Larry Hudson <orgnut@yahoo.com> - 2013-12-25 00:13 -0800
  Re: Variables in a loop, Newby question vanommen.robert@gmail.com - 2013-12-27 00:53 -0800
    Re: Variables in a loop, Newby question Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-27 11:39 -0500

csiph-web