Skip to content

HFPY CH 1

Jacob Amey edited this page Aug 23, 2013 · 6 revisions

Chapter 1 - Everyone loves lists

(meet python)

32 Pages Long

Description:

In this chapter you mainly work with lists. Throughout the course of the chapter though you cover while and for loops as well as functions and if then else statements. At the end you get a small taste of recursion! All in all a very fun chapter that covered lists in detail.

The Code:

You create a small application for a movie buff that will process his collection of Movie data. In the end you create a function that recursively moves through his data that you have listed out. it works great with a small amount of code. I need to look into recursion more since I myself still don't really get it!

Python Lingo:

  1. "BIF" a built in function.
  2. "Suite" - a block of Python code, which in indented to indicate grouping.
  3. "Batteries included" - a way of referring to the fact that python comes with most everything you'll need to get going quickly and productively.

IDLE Notes:

  1. The IDLE shell lets you experiment with your code as you write it.
  2. Adjust IDLE's preferences to suit the way you work.
  3. Remember: when working with the shell, use ALT-P for Previous and use ALT-N for Next.

Python Tools Covered:

  • Run Python 3 from the command line or from within IDLE or your chosen IDE.
  • Identifiers are names that refer to data objects. The identifiers have no "type," but the data objects that they refer to do.
  • print() BIF displays a message on screen.
  • a list is a collection of data, separated by commas and surrounded by square brackets.
  • Lists are like arrays on steroids.
  • Lists can be used with BIFs, but also support a bunch of lists methods.
  • Lists can hold any data, and the data can be of mixed type. Lists can also hold other lists.
  • Lists shrink and grow as needed. All of the memory used by your data is managed by Python for you.
  • Python uses indentation to group statements together.
  • len() BIF provides a length of some data object or count the number of items in a collection, such as a list.
  • the for loop lets you iterate a list and is often more convenient to use than an equivalent while loop.
  • 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.
Clone this wiki locally