Академический Документы
Профессиональный Документы
Культура Документы
Books:
Python
Dive into Python - Mark Pilgrim (http://www.diveintopython.org)
A Byte of Python – Swaroop C S (http://www.ibiblio.org/swaroopch/byteofpython/read/)
Think like a Python programmer – Allen Downey (http://www.greenteapress.com/thinkpython/thinkCSpy/ )
Collective Intelligence
Programming Collective Intelligence, Building Smart Web 2.0 Applications - Toby Segaran
NLTK
Natural Language Processing in Python - Steven Bird, Ewan Klein, and Edward Loper (http://nltk.org/index.php/Book)
Required Reading:
wikipedia.org
google.com
python.org
nltk.org
Course Group:
http://groups.google.com/group/pesit-2008-course
Unix:
sh, bash etc
mostly default way to interact with the OS, unless one uses X-Windows
Windows
cmd.exe
Mac
Any mac users?
Exercise:
Installation:
Exercise:
2. Open command line and check if python is available. How do you do this?
The python program is called “python.exe” on windows
3. Add python to PATH (if it is not added to it already). What is the PATH?
So what are the advantages of compiled language vs interpreted and vice versa?
Exercise:
1. Start a python shell session. You will see the shell prompt:and execute:
>>>
2. Now type print “hello world!” and enter
>>> print “hello world”
3. What happened?
You would you seen “hello world” being printed onto the console
hello world
2. Now exit the sheel, open a new file hello.py using your favourite editor. Type print “hello world from script” and
save the file. Use python.exe to run this file from the command shell
cmd> python hello.py
What happened?
Python interpreter (continued):
python scripts use extension of .py (convention). You can have any other extension as well, but don't change
convention just to be different. It is not as cool.
Using help
Python help is available online. We can also get help locally. For this we may need to install documentation
locally.
Exercise:
Values have a type. Types denote the category of the value. Types can be primitives like numbers(integer, float),
strings, data-structures (list, dictionary, tuples), files
>>> type(1)
<type 'int'>
>>> type(“hello”)
<type 'string'>
>>> type(“3.14”)
Exercises:
so hello is variable. Notice that we did not assign a type to the variable. Python figures it out. Hence it is called a
dynamic language.
variables are powerful as they store the value and allow for its manipulation
Naming variables
there are a few rules for naming variables. Let us find out what some of these are by trial and error
Exercises:
What happened?
Variable naming rules:
(underscore or letter) + (any number of letters, digits, or underscores)
case matters
reserved words (keywords) not allowed
Examples:
name, _name, name1, name_1 (good)
name$, 1name, 1_name (bad)
break,except,import,print,class,exec,in,raise,continue,finally,is,return,def,for,lambda,try,and,del,from,not,while,as
,elif,global,or,with,assert,else,if,pass,yield
Exercises:
A variable (which is just a name) does not “carry” the type with it. It just has the type most recently associated
with it. Remember python is a dynamically typed language!
Statements: an instruction that the python interpreter can execute
Examples:
print “hello”
a=1
Examples:
mathematical (+,-,x,/)
logical (and, or)
Examples:
>>> 1 + 1
>>> selling_price = cost_price – discount
Comments: notes to help humans understand the program. The computer (python interpreter) will ignore it
Exercises: