Python 101 (.pdf) - JMU CS Department

115 downloads 3167 Views 98KB Size Report
Home page: http://www.python.org/. Slides adapted from ... """Simple demo of the Caesar Cipher.""" def encrypt(msg ... Tutorial: http://docs.python.org/2/tutorial/.
What is Python? I

Object-oriented, rapid prototyping language

I

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

I

Interpreted and interactive; very easy to learn

I

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/

Slides adapted from originals by Dr. Mayfield. Thanks!

Python 101

1

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)

2

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 ’