1. Modules If you quit from the Python interpreter and enter it again, the definitions you have made (functions and variables) are lost. Therefore, if you want to write a somewhat longer program, you are better off using a text editor to prepare the input for the interpreter and running it with that file as input instead. This is known as creating a script . As your program gets longer, you may want to split it into several files for easier maintenance. You may also want to use a handy function that you’ve written in several programs without copying its definition into each program. To support this, Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. Such a file is called a module ; definitions from a module can be imported into other modules or into the main module (the collection of variables that you have access to in a script executed at the top level and in calculator mode). A module is a file containing ...
1. Lists The list data type has some more methods. Here are all of the methods of list objects: list. append ( x ) Add an item to the end of the list. Equivalent to a[len(a):] = [x] . list. extend ( iterable ) Extend the list by appending all the items from the iterable. Equivalent to a[len(a):] = iterable . list. insert ( i , x ) Insert an item at a given position. The first argument is the index of the element before which to insert, so a.insert(0, x) inserts at the front of the list, and a.insert(len(a), x) is equivalent to a.append(x) . list. remove ( x ) Remove the first item from the list whose value is equal to x . It raises a ValueError if there is no such item. list. pop ( [ i ] ) Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns the last item in the list. (The square brackets around the i in the method signature denote that the parameter is optional, not that you should ...