12
Introduction to Python: Slides Referenced in Homework 0 CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth January 2005

Introduction to Python: Slides Referenced in Homework 0 CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth January 2005

Embed Size (px)

Citation preview

Page 1: Introduction to Python: Slides Referenced in Homework 0 CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth January 2005

Introduction to Python:Slides Referenced in Homework 0

CSE-391: Artificial IntelligenceUniversity of Pennsylvania

Matt Huenerfauth

January 2005

Page 2: Introduction to Python: Slides Referenced in Homework 0 CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth January 2005

What is Python?

• A programming language with strong similarities to PERL, but with powerful typing and object oriented features. – Commonly used for producing HTML content

on websites. Great for text files.– Useful built-in types (lists, dictionaries).– Clean syntax, powerful extensions.

Page 3: Introduction to Python: Slides Referenced in Homework 0 CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth January 2005

Why Python for CSE-391?

• Textbook Code: Very Object Oriented– Python much less verbose than Java

• AI Processing: Symbolic– Python’s built-in datatypes for strings, lists, and more.

– Java or C++ require the use of special classes for this.

• AI Processing: Statistical– Python has strong numeric processing capabilities:

matrix operations, etc.

– Suitable for probability and machine learning code.

Page 4: Introduction to Python: Slides Referenced in Homework 0 CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth January 2005

Before we get started…

Page 5: Introduction to Python: Slides Referenced in Homework 0 CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth January 2005

Homework 0: Learning Python

• Unfortunately, we won’t have time to cover all of Python in class; so, we’re just going to go over the highlights. – You’ll need to learn more on your own. – Homework 0 asks you to install Python or get

comfortable using it on Eniac. It also asks you to read some online Python tutorials.

– Later homeworks will include Python programming exercises to help you practice.

Page 6: Introduction to Python: Slides Referenced in Homework 0 CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth January 2005

Homework 0: Python Tutorials

You should definitely read these…• “Dive into Python” (Chapters 2 to 4)

http://diveintopython.org/

• Python 101 – Beginning Pythonhttp://www.rexx.com/~dkuhlman/python_101/python_101.html

You should browse these and refer to them…• The Official Python Tutorial

http://www.python.org/doc/current/tut/tut.html

• The Python Quick Reference http://rgruet.free.fr/PQR2.3.html

Page 7: Introduction to Python: Slides Referenced in Homework 0 CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth January 2005

Homework 0: Official Handout

• There’s an official handout for Homework 0 (available on the class website) that describes the assignment in more detail.– There is some Python code to submit.– There are some questions to answer about the

readings.

Page 8: Introduction to Python: Slides Referenced in Homework 0 CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth January 2005

Technical Issues

Page 9: Introduction to Python: Slides Referenced in Homework 0 CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth January 2005

Installing Python

• Python is on eniac: /pkg/bin/python

• Python for Win/Mac from www.python.org.

• GUI development environment: IDLE.

Credits:http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html

Page 10: Introduction to Python: Slides Referenced in Homework 0 CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth January 2005

IDLE Development Environment

• Shell for interactive evaluation.

• Text editor with color-coding and smart indenting for creating python files.

• Menu commands for changing system settings and running files.

• You’ll see me using IDLE in class.

Page 11: Introduction to Python: Slides Referenced in Homework 0 CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth January 2005

Running Interactively on UNIX

On Unix…

% python

>>> 3+3

6

The ‘>>>’ is the Python prompt. In Unix, when finished, you can use CONTROL+D.

Page 12: Introduction to Python: Slides Referenced in Homework 0 CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth January 2005

Running Programs on UNIX

% python filename.py

You can create python files using emacs.

(There’s a special Python editing mode.)

You could even make the *.py file executable and add the following text to top of the file to make it runable: #!/pkg/bin/python