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: 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." 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" 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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/