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