840 likes | 2.18k Views
Lists in Python. List methods and functions. List methods. Notes about methods. These methods, append, sort, reverse, all change the original list. If you need to retain the original list as well as keep the resulting list, use sorted( listname ) and list(reversed( listname ))
E N D
Lists in Python List methods and functions
Notes about methods • These methods, append, sort, reverse, all change the original list. • If you need to retain the original list as well as keep the resulting list, use sorted(listname) and list(reversed(listname)) • Just as with strings, index will cause an exception and program crash if its search fails
Notes about functions and methods • When the previous two tables say “items must be comparable”, it means they must all be of numeric type, or they must all be strings. Mixing them will cause an exception and crash • When they say “in place” it means that it will change the original list. • For the sum function, items can be integer or float