6.3 ListsList objects hold ordered sequences of other Pyxplot objects, which may include lists and dictionaries to create hierarchical data structures. They are created by enclosing a comma-separated list of objects by square brackets. For example: a = [10,colors.green,"bottles"] Once created, more items can be added to a list using its append(item) and insert(n,item) methods, where the latter inserts an item at position : pyxplot> theFive = ["Cui","Mussorgsky"] A complete list of the methods available on lists (itself a list of strings) can be found by calling the method [].methods(); they are also listed in Section 13.10. As with string methods, documentation of list methods is returned if the method object is printed: pyxplot> print [].append Most methods that operate on lists, for example, append, extend and sort operations, return the list as their output. Unless this is stored in a variable, Pyxplot prints this return value to the terminal. In some cases this is useful: in the example above, it allowed us to see how the list was changing when we called its append() and insert() methods. Often, however, this terminal spam is unwanted. The call command allows methods to be called without printing their output, which is discarded: pyxplot> a = ["William I"]
|