Wednesday, March 10, 2010

Python 3, Part 5 (List Methods)

In Part 4, we saw how to use slicing to work with parts of a string, list, or tuple, as well as how to insert, delete, and add to these types of variables. Python has a number of built in methods -- also called functions -- that can do these operations in a way that makes the code easier to read. Sometimes it's a bit hard to understand all those colons and square brackets, and it's easier to use words like append, remove, or insert, which are, indeed the names of methods associated with lists. We'll also see how these easy to understand methods can be used to build a simple stack (where the last element added is the first element retrieved) or queue (where the first element added is the first element retrieved). We'll also discover how to sort, count, and locate items in a list. Along the way, we'll learn about the autocomplete feature of Blender's Python console, a handy feature that documents available methods.