More on Python..

Filed under dev
Tagged as

This is hardly interesting pressing news, but it’s left an impression on me, so I choose to share:   In my tinkering with python, I’ve found the python console to be a priceless tool when helping to discover syntax.  In this afternoon’s example, I was wondering about different cute ways to loop through lists, so I drop to a prompt, type python, hit enter, and:

>>> a = [1, 2, 3]
>>> a.append(4)
>>> print a
[1, 2, 3, 4]
>>> while 7 not in a:
...   a.append(int(raw_input('append?')))
...
append?4
append?3
append?5
append?6
append?7
>>> print a
[1, 2, 3, 4, 4, 3, 5, 6, 7]
>>>

OK, that skips the step where I googled, saw an example, and then wanted to try it out in a simple cases to make sure I got it.  But this still demonstrates the value, right?

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*