Download Python

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Python
Joseph Eckstrom, Benjamin Moore, Willis
Kornegay
Overview
• Written to improve programmer productivity
• Python gives programmers the option to use objectoriented, structured or functional programming
paradigms.
• Trades some speed for productivity
• In era of fast machines, acceptable
History
• Written at CWI, Netherlands, by Guido van Rossum
• Named BDFL, or “Benevolent Dictator for Life” by
Python community
• Based on ABC, but ABC had drawbacks
• Monolithic design not adaptable
• Could not access file system or O.S.
Evolution
• Python 1.0
• Classes, inheritance, functional programming
• Python 2.0
• Garbage collection, list comprehensions, Haskell-like
syntax
• Python 3.0
• Refinement of existing features, overhauls to standard
libraries
Language Concepts
• High level, interpreted language
• Supports multiple paradigms
• OO, Imperative, Functional
• No semicolons at the end of lines
• Blocks represented by indentations
Examples of Use – Lambda
Functions
>>> def make_incrementor (n): return lambda x: x + n
...
>>> f = make_incrementor(2)
>>> g = make_incrementor(6)
>>> print(f(42), g(42))
44 48
>>> print(make_incrementor(22)(23))
45
Examples of Use – Lists
>>> S = [x**2 for x in range(10)]
>>> V = [2**i for i in range(13)]
>>> M = [x for x in S if x % 2 ==0]
>>> print(S); print(V); print(M)
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]
[0, 4, 16, 36, 64]
Examples of Use – Classes
>>> class MyClass:
...
# A simple example class
…
i = 12345
…
def f(self):
…
return “Hello, world.”
…
>>> x = Myclass()
>>> x.f()
Hello, world.
Comparison - Ruby
• Both imperative/functional, object oriented, &
interpreted
• Python emphasizes a single best way, and
features extensive standard libraries
• Ruby emphasizes elegant syntax & greater
object-orientation
Comparison – C++
• Both object-oriented, imperative languages
• C++ compiled to hardware native code; Python
compiled to bytecode, executed by VM
• Both languages are flexible in terms of objectorientation.