Introduction to Python

adventurescoldΛογισμικό & κατασκευή λογ/κού

7 Νοε 2013 (πριν από 3 χρόνια και 9 μήνες)

105 εμφανίσεις

Introduction to Python
Girls'Programming Network
School of Information Technologies
University of Sydney
Mini-Lecture 1
Python
Install
Running
Summary 2
Outline
1
What is Python?
2
Installing Python
3
Running Python
4
Summary
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 3
There are many dierent kinds of programming languages
Programming languages taught in schools include:

Visual Basic (and Visual Basic.NET)
 C#

Java
 Python
 ColdFusion
To run programs written in some of these languages you will need
a program called a compiler.The compiler checks that your
program is syntactically correct and then creates an executable
version that your computer understands.
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 4
We are going to learn Python
 Python programs do not need to be compiled - instead they
are run by the Python interpreter.
http://xkcd.com
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 5
Python was developed by Guido van Rossum
 started over the Christmas break 1989
 developed in the early 1990s

while Guido was at CWI and CNRI
 name from Monty Python's Flying Circus

Guido is known as the Benevolent
Dictator for Life (bdfl),meaning that
he continues to oversee Python's
development.
http://www.python.org/
~
guido/
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 6
Python inherits from abc
 Guido previously worked on abc at CWI in the early 1980s

abc was designed for beginners and non-professionals

abc placed a high value on clarity:

blocks identied by indentation

minimal use of punctuation

one preferred way of doing things
 but lacked extensibility and used idiosyncractic syntax and
terminology
 Python was designed to appeal to the Unix/C community
http://www.python.org/doc/essays/foreword/
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 7
So why use Python?
 the clean simple syntax is very easy to read and write
it has been called executable pseudo-code
 it encourages good programming habits

it still has a lot of power and features:
objects,exceptions,generators,iterators,threads,...
 but these don't get in the way of beginners

and a huge standard library (batteries included):
re,os,email,urllib,bsddb

Python scripts are portable to anywhere the interpreter runs
 and the interpreter is freely available for:
Windows 95-XP/CE,Mac (0S 9-X),any Unix,Amiga,JVM,...
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 8
Still not convinced?
 Python lets you get on with writing interesting programs

Python programming is fun!
[Python is] the most ecient language I've ever used.It's 10 times better
than any of the other tools I have used.It's free,it's object-oriented,it
adapts to everything,it runs on everything.There is almost an
indescribable,'quality without a name'attraction on my part
Bruce Eckel,author of Thinking in C++,Thinking in Java
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 9
Lots of big organisations are using Python
Python is everywhere at ilm.It's used to extend the capabilities of our
applications,as well as providing the glue between them.Every cg image
we create has involved Python somewhere in the process.
Philip Peterson,Principal Engineer R&D,Industrial Light & Magic.
Python has been an important part of Google since the beginning,and
remains so as the system grows and evolves.Today dozens of Google
engineers use Python,and we're looking for more people with skills in
this language.
Peter Norvig,Director of Search Quality,Google.
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 10
Download Python from the website
 run the Windows installer from http://www.python.org
 Python 2.5.2 is the latest version (10.8MB)
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 11
Installing Python
 if possible install Python as user Administrator

it's best to install it in the default C:\Python25 location
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 12
Version confusion!
 Don't get Python 2.6a

Don't get Python 3.0 (a.k.a.Python 3000)
 Python is changing over the next couple of years

Don't worry,you'll be able to learn the new ways of doing
things easily.
 Use the current stable version (2.5.2) for now!
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 13
Running Python
 Under Unix/Linux,just type python at the shell prompt
 Under Windows,you can run it from a command shell:
 goto Start j Run,and enter cmd,and press OK.
 then type python
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 14
Running the Integrated DeveLopment Environment
 idle is an ide for Python written in Python
 Under Unix/Linux,just type idle at the shell prompt

Under Windows,goto Start j Programs j Python2.5
and select IDLE (Python GUI):
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 15
Hello World is tiny in Python
 Hello World is the canonical rst program to write

In Python,Hello World is only one line!
 You can type it directly into the Python interpreter:
1 >>> print"hello world"
2 hello world
3 >>>

The colours in this (and all examples) matches the syntax
highlighting that idle produces.
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 16
Hello World in idle
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 17
Writing Python in idle
 idle is an ide for Python written in Python
 Under Unix/Linux,just type idle at the shell prompt
 Under Windows,goto Start j Programs j Python2.5
and select IDLE (Python GUI):
Girls'Programming Network
Introduction to Python Mini-Lecture 1
Python
Install
Running
Summary 18
You should now be able to:
 Convince everyone to code in Python:)

Install and run the Python interpreter under Windows
 Enter simple statements into the interactive Python Shell
Girls'Programming Network
Introduction to Python Mini-Lecture 1