Introduction to Python  
 
 

Lesson 2

Readings:
All of this week's readings will be taken from Python Programming from Wikibooks.

  • Variables: Variables in Python are dynamically typed. This means that you do not have to declare what type of object they will represent before the variable (e.g in Java int x = 5 would mean that x can only hold an integer, but in Python you only need to code x = 5 and later you could go on to code x = [1,2,3] and Python would now recognize x as a list.). There are many basic data types that can be assigned to a variable in Python and they are listed here: Data Types. The following links should better introduce you to some of the more common data types and their capabilities and syntax.
  • Functions
  • Classes: Read Sections 1-3 of Classes
  • Standard Library/Modules

Key Concepts:

  • Variables and the standard Data Types
  • Creating your own classes
  • Adding methods
  • Standard library

Exercises:
Create a class that has methods performing the basic mathematical operators: +, -, *, /, %, and sqrt() (you will need to use the math module for this) on two arguments. Try the methods out on arguments of varying data types (remember you don't have to create a new method for each different combination of data types as Python is dynamically typed) and analyze the results.


Files to Be Downloaded