What is Python? - JMU CS Department

7 downloads 4715 Views 127KB Size Report
Python vs Java. Python. ▷ Dynamically typed (assign names to objects) ... """ Simple demo of the Caesar Cipher.""" ... Tutorial: http://docs.python.org/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?

Python 101

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 (Linux installation tools)

I

LLNL, Fermilab (steering scientific applications)

I

More success stories at http://www.pythonology.com/ 2

Python vs Java Python

Java

I

Dynamically typed (assign names to objects)

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”

myFile = open ( " d . txt " )

i m p o r t java . io .*; ... BufferedReader myFile = new BufferedReader ( new FileReader ( " d . txt " ));

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

3

Some Basics

Python 101

I

Indentation matters (no braces!)

I

Type matters (must be consistent)

I

Comments start with #

I

Strings use ’s or ”s (or ”””s)

I

None ≈ null, self ≈ this

I

and, or, not instead of &&, ||, !

I

print statement

I

[1, 2, 3] is a list

4

Discete Math Example """ Simple demo of the Caesar Cipher . """ d e f encrypt ( msg , k ): """ Shifts msg by k letters , ignoring spaces . """ ans = " " f o r c i n msg : i f ’a ’