Presentation is loading. Please wait.

Presentation is loading. Please wait.

Scott G. Ainsworth for ODU ACM 22 Sept 2011

Similar presentations


Presentation on theme: "Scott G. Ainsworth for ODU ACM 22 Sept 2011"— Presentation transcript:

1 Scott G. Ainsworth for ODU ACM 22 Sept 2011
Python Scott G. Ainsworth for ODU ACM 22 Sept 2011

2 What is Python? Easy to learn Simple syntax Dynamic typing
High-level data structures Free Linux/Unix, OS X, Windows MIT’s language of choice Relationship to other languages

3 Why Python? Fast development cycle
Interactive & edit, debug/run vs. edit, compile, debug/run Extensive standard and add-on libraries (MIT’s language of choice) Python, Jython, & IronPython Google AppEngine

4 Basic Syntax Block structured But no braces Indent defines blocks
def fib(n): a, b = 0, 1 while b < n: print b, a, b = b, a+b Quick introduction to the syntax

5 Numbers & Strings Integers: -231 – 231-1 5 + 23 Long: unlimited
Boolean: True or False 0 or 1 Real and Complex: 1.25 / 6.3 Complex(1.1,2.2) 'value' == "value" """multiple lines""" u'unicode' 'substring'[2:5] == 'bst'

6 Sequence Types Lists Tuples
primes = [ 2, 3, 5, 7, 11, 13, 17, 19, 23 ] primes.append(27) Primes[-2:] = [ 23, 27 ] Tuples primes = ( 2, 3, 5, 7, 11, 13, 17,19, 23 ) primes.append(27) # fails, tuples are immutable primes[-2:] = ( 23, 27 ) Strings are an immutable list of single characters Lists, tuples, dictionaries, & strings

7 Dictionaries & Sets Dictionaries Sets
pdict = { "p1" : 2, "p2" : 3, "p3" : 5 } pdict["p4"] = 7 pdict["p2"] == 3 Sets primes = Set([ 2, 3, 5, 7, 11, 13, 17,19, 23 ]) primes.append(27) # fails, set are unordered primes.add(27) # succeeds Lists, tuples, dictionaries, & strings

8 Classes Class complex: """implement complex numbers""" def __init__(self, r, i): self.__r = r self.__i = i def isreal(self): return self.c == def __add__(self, c): return complex(self.r + c.r, self.i + c.i)

9 Memento & Timemap for www.cs.odu.edu
< rel="original", < rel="timemap"; type="application/link-format”, < rel="first memento"; datetime="Thu, 02 Jan :01:37 GMT”, < >; rel="memento"; datetime="Fri, 06 Jun :50:39 GMT", Output from timemap.py test Original: Time Map: First Memento: (datetime.datetime(1997, 1, 2, 13, 1, 37, tzinfo=tzutc()), ' :50:39+00:00 =

10 timemap.py Output Original: Time Bundle: Time Gate: Time Map: First Memento: :01:37+00:00 Last Memento: :58:31+00:00 Mementos: :50:39+00:00 = / :16:32+00:00 = /

11 Code Walk Through class TimeMap: Memento timemap container class
class TimeMapTokenizer: Helper class to tokenize a link-style timemap __main__: Used for quick unit testing Download the code:

12 Summary Easy to learn Dynamic typing High-level data structures Free
Linux/Unix, OS X, Windows Fast development cycle Extensive standard and add-on libraries Widely-supported Relationship to other languages

13 Questions? ?

14 Links Slides: Code: Python: Python Docs: Python Libraries:


Download ppt "Scott G. Ainsworth for ODU ACM 22 Sept 2011"

Similar presentations


Ads by Google