What is Python? - JMU CS Department

7 downloads 2767 Views 131KB Size Report
Python vs Java. Python. ▷ Dynamically typed. (assign names to values) ... """ Simple demo of the Caesar Cipher.""" ... Tutorial: http://docs.python.org/2/tutorial/.
What is Python?

Python 101

I

Object-oriented, rapid prototyping language

I

Multi-purpose: Web, GUI, scripting, science, etc.

I

Interpreted and interactive; very easy to learn

I

Strongly typed and dynamically typed

I

Focus on readability and productivity

I

Extensive standard library and community

I

CPython, Jython, IronPython, PyPy, etc.

I

Home page: http://www.python.org/

1

Who uses Python? I

Google (various projects)

I

NASA (several projects)

I

NYSE (one of only three languages “on the floor”)

I

Industrial Light & Magic (everything)

I

Yahoo! (Yahoo mail & groups)

I

RealNetworks (function and load testing)

I

RedHat and Ubuntu (Linux installation tools)

I

LLNL, Fermilab (steering scientific applications) More success stories at http://www.pythonology.com/

Python 101

2

Python vs Java Python

Java

I

Dynamically typed (assign names to values)

I

Statically typed (must declare variables)

I

Concise: “expressing much in a few words; implies clean-cut brevity, attained by excision of the superfluous”

I

Verbose: “abounding in words; using or containing more words than are necessary”

# open the file d . txt myFile = open ( " d . txt " )

import java . io .*; ... // open the file d . txt BufferedReader myFile = new BufferedReader ( new FileReader ( " d . txt " ));

http://pythonconquerstheuniverse.wordpress.com/category/java-and-python/ Python 101

3

Some Basics I

Indentation matters (no braces!)

I

Type matters (must be consistent)

I

Comments start with a #

I

Strings use ’s or "s (or """s)

I print I None

(vs System.out.println)

≈ null, self ≈ this

I and, or, not I [1, 2, 3]

Python 101

instead of &&, ||, !

is a list (≈ ArrayList)

4

Discete Math Example """ Simple demo of the Caesar Cipher . """ def encrypt ( msg , k ): """ Shifts msg by k letters , ignoring spaces . """ ans = " " for c in msg : if ’a ’