[Tutor] i++

scott slewin at rogers.com
Tue Jun 5 17:13:06 CEST 2007


Danny Yoo wrote:
> 
>>     is there any way in Python to simply add or subtract one from a 
>> variable like i++ or i--?  I don't mind doing a i = i + 1, but would 
>> prefer something more simple and faster.
> 
> Out of curiosity, why are you incrementing variables?
Actually, it is mostly just my curiosity :)  I'm designing my first 
major Python program (It will run a EnGarde PBEM for me).  I had to make 
a loop to loop around 5 times and was going to use the i += 1 when I 
remembered range :)  I did the following instead and it worked perfectly.

for l in range(1,6):
     print l

I will, eventually, be needing the i+= 1 as in the game many times I 
will needing to take away or add to attributes.  I have attached what I 
got so far if you feel like taking a look, but it is probably nasty by 
your standards :)

Thanks everyone for your answers.  I'll probably have a few more 
questions before I finish this project.

-- 
Your friend,
Scott

Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: engarde.py
Type: text/x-python
Size: 10938 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20070605/b7e07f92/attachment.py 


More information about the Tutor mailing list