Page 68 -
P. 68

python toolbox


                       Your Python Toolbox


                       You’ve got Chapter 1 under your
                       belt and you’ve added some key                 ƒ  Run Python 3 from the command line or
     CHAPTER 1                                                        ƒ  Identifiers are names that refer to data   CHAPTER 1
                                                                      from within IDLE.
                       Python goodies to your toolbox.
                                                                      objects. The identifiers have no “type,” but
                                                                      the data objects that they refer to do.


             Python Lingo                                             ƒ   ƒ  print() BIF displays a message on
                                                                      screen.
                                                                      A list is a collection of data, separated
             • “BIF” - a built-in function.                           by commas and surrounded by square
                                                                      brackets.
             • “Suite” - a block of Python code, which                ƒ  Lists are like arrays on steroids.
             is indented to indicate grouping.                        ƒ  Lists can be used with BIFs, but also

              • “Batteries included” - a way of                       support a bunch of list methods.
              referring to the fact that Python comes                 ƒ  Lists can hold any data, and the data can be
              with most everything you’ll need to get                 of mixed type. Lists can also hold other lists.
              going quickly and productively.                         ƒ  Lists shrink and grow as needed. All of the

                                                                      memory used by your data is managed by
                       IDLE Notes                                     ƒ  Python for you.
                                                                      Python uses indentation to group statements
                                                                      together.
                      • The IDLE shell lets you experiment with
                      your code as you write it.                      ƒ  len() BIF provides a length of some data
                                                                      object or count the number of items in a
                      • Adjust IDLE’s preferences to suit the         collection, such as a list.
                      way you work.
                                                                      ƒ  The for loop lets you iterate a list and
                                                                      is often more convenient to use that an
                      • Remember: when working with the shell,
                                                                      equivalent while loop.
                      use Alt-P for Previous and use Alt-N for
                     Next (but use Ctrl if you’re on a Mac).          ƒ  The if... else... statement lets you make
                                                                      decisions in your code.
                                                                      ƒ  isinstance() BIF checks whether
                                                                      an identifier refers to a data object of some
                                                                      specified type.
                                                                      ƒ  Use def to define a custom function.







           32    Chapter 1
   63   64   65   66   67   68   69   70   71   72   73