SlideShare a Scribd company logo
Nov 6, 2014
Python 
By 
AAddddrreessss:: 
KK11// 44,, SSeeccoonndd fflloooorr,, 
SSeeccttoorr--1155//1166 MMaarrkkeett,, 
VVaasshhii,, NNaavvii MMuummbbaaii 
MMoobb NNoo:: 
99889922990000110033 
99889922990000117733
Introduction 
 Most recent popular 
(scripting/extension) language 
 although origin ~1991 
 heritage: teaching language (ABC) 
 Tcl: shell 
 perl: string (regex) processing 
 object-oriented 
 rather than add-on (OOTcl)
Python philosophy 
 Coherence 
 not hard to read, write and maintain 
 power 
 scope 
 rapid development + large systems 
 objects 
 integration 
 hybrid systems
Python features 
no compiling or linking rapid development cycle 
no type declarations simpler, shorter, more flexible 
automatic memory management garbage collection 
high-level data types and 
operations 
object-oriented programming code structuring and reuse, C++ 
embedding and extending in C mixed language systems 
classes, modules, exceptions "programming-in-the-large" support 
dynamic loading of C modules simplified extensions, smaller 
dynamic reloading of C modules programs can be modified without 
Nov 6, 2014 Advanced 
fast development 
binaries 
stopping 
Programming 
Lutz, Programming Python
Python features 
Lutz, Programming Python 
universal "first-class" object model fewer restrictions and rules 
run-time program construction handles unforeseen needs, end-user 
coding 
interactive, dynamic nature incremental development and 
testing 
access to interpreter information metaprogramming, introspective 
objects 
wide portability cross-platform programming 
without ports 
compilation to portable byte-code execution speed, protecting source 
code 
built-in interfaces to external 
services 
system tools, GUIs, persistence, 
databases, etc.
Python 
 elements from C++, Modula-3 
(modules), ABC, Icon (slicing) 
 same family as Perl, Tcl, Scheme, 
REXX, BASIC dialects 
Nov 6, 2014 Advanced 
Programming
Uses of Python 
Advanced 
Programming 
 shell tools 
 system admin tools, command line programs 
 extension-language work 
 rapid prototyping and development 
 language-based modules 
 instead of special-purpose parsers 
 graphical user interfaces 
 database access 
 distributed programming 
 Internet scripting
What not to use Python (and 
kin) for 
 most scripting languages share these 
 not as efficient as C 
 but sometimes better built-in algorithms 
(e.g., hashing and sorting) 
 delayed error notification 
 lack of profiling tools 
Nov 6, 2014 Advanced 
Programming
Using python 
 /usr/local/bin/python 
 #! /usr/bin/env python 
 interactive use 
Python 1.6 (#1, Sep 24 2000, 20:40:45) [GCC 2.95.1 19990816 (release)] on sunos5 
Copyright (c) 1995-2000 Corporation for National Research Initiatives. 
All Rights Reserved. 
Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam. 
All Rights Reserved. 
>>> 
 python –c command [arg] ... 
 python –i script 
 read script first, then interactive 
Nov 6, 2014 Advanced 
Programming
Python structure 
 modules: Python source files or C extensions 
 import, top-level via from, reload 
Advanced 
Programming 
 statements 
 control flow 
 create objects 
 indentation matters – instead of {} 
 objects 
 everything is an object 
 automatically reclaimed when no longer needed
First example 
#!/usr/local/bin/python 
# import systems module 
import sys 
marker = '::::::' 
for name in sys.argv[1:]: 
input = open(name, 'r') 
print marker + name 
print input.read() 
Nov 6, 2014 Advanced 
Programming
Basic operations 
Nov 6, 2014 Advanced 
Programming 
 Assignment: 
 size = 40 
 a = b = c = 3 
 Numbers 
 integer, float 
 complex numbers: 1j+3, abs(z) 
 Strings 
 'hello world', 'it's hot' 
 "bye world" 
 continuation via  or use """ long text """"
String operations 
 concatenate with + or neighbors 
 word = 'Help' + x 
 word = 'Help' 'a' 
 subscripting of strings 
 'Hello'[2]  'l' 
 slice: 'Hello'[1:2]  'el' 
 word[-1]  last character 
 len(word)  5 
 immutable: cannot assign to subscript 
Advanced 
Programming
Lists 
 lists can be heterogeneous 
 a = ['spam', 'eggs', 100, 1234, 2*2] 
 Lists can be indexed and sliced: 
 a[0]  spam 
 a[:2]  ['spam', 'eggs'] 
 Lists can be manipulated 
 a[2] = a[2] + 23 
 a[0:2] = [1,12] 
 a[0:0] = [] 
 len(a)  5 
Nov 6, 2014 Advanced 
Programming
Basic programming 
a,b = 0, 1 
# non-zero = true 
while b < 10: 
# formatted output, without n 
print b, 
# multiple assignment 
a,b = b, a+b 
Nov 6, 2014 Advanced 
Programming
Control flow: if 
x = int(raw_input("Please enter #:")) 
if x < 0: 
x = 0 
print 'Negative changed to zero' 
Nov 6, 2014 Advanced 
Programming 
elif x == 0: 
print 'Zero' 
elif x == 1: 
print 'Single' 
else: 
print 'More' 
 no case statement
Control flow: for 
a = ['cat', 'window', 'defenestrate'] 
for x in a: 
print x, len(x) 
 no arithmetic progression, but 
 range(10)  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 
 for i in range(len(a)): 
print i, a[i] 
 do not modify the sequence being iterated 
over 
Nov 6, 2014 Advanced 
Programming
Loops: break, continue, else 
 break and continue like C 
 else after loop exhaustion 
for n in range(2,10): 
for x in range(2,n): 
if n % x == 0: 
print n, 'equals', x, '*', n/x 
break 
Nov 6, 2014 Advanced 
Programming 
else: 
# loop fell through without finding a factor 
print n, 'is prime'
Do nothing 
 pass does nothing 
 syntactic filler 
while 1: 
Advanced 
Programming 
pass
Defining functions 
Nov 6, 2014 Advanced 
Programming 
def fib(n): 
"""Print a Fibonacci series up to n.""" 
a, b = 0, 1 
while b < n: 
print b, 
a, b = b, a+b 
>>> fib(2000) 
 First line is docstring 
 first look for variables in local, then global 
 need global to assign global variables
Functions: default argument 
values 
def ask_ok(prompt, retries=4, 
complaint='Yes or no, please!'): 
Nov 6, 2014 Advanced 
Programming 
while 1: 
ok = raw_input(prompt) 
if ok in ('y', 'ye', 'yes'): return 1 
if ok in ('n', 'no'): return 0 
retries = retries - 1 
if retries < 0: raise IOError, 
'refusenik error' 
print complaint 
>>> ask_ok('Really?')
Keyword arguments 
 last arguments can be given as keywords 
def parrot(voltage, state='a stiff', action='voom', 
type='Norwegian blue'): 
print "-- This parrot wouldn't", action, 
print "if you put", voltage, "Volts through it." 
print "Lovely plumage, the ", type 
print "-- It's", state, "!" 
parrot(1000) 
parrot(action='VOOOM', voltage=100000) 
Nov 6, 2014 Advanced 
Programming
Lambda forms 
 anonymous functions 
 may not work in older versions 
def make_incrementor(n): 
return lambda x: x + n 
f = make_incrementor(42) 
f(0) 
f(1) 
Advanced 
Programming
List methods 
Nov 6, 2014 Advanced 
Programming 
 append(x) 
 extend(L) 
 append all items in list (like Tcl lappend) 
 insert(i,x) 
 remove(x) 
 pop([i]), pop() 
 create stack (FIFO), or queue (LIFO)  pop(0) 
 index(x) 
 return the index for value x
List methods 
Nov 6, 2014 Advanced 
Programming 
 count(x) 
 how many times x appears in list 
 sort() 
 sort items in place 
 reverse() 
 reverse list
Functional programming 
tools 
 filter(function, sequence) 
def f(x): return x%2 != 0 and x%3 0 
filter(f, range(2,25)) 
 map(function, sequence) 
 call function for each item 
 return list of return values 
 reduce(function, sequence) 
 return a single value 
 call binary function on the first two items 
 then on the result and next item 
 iterate 
Nov 6, 2014 Advanced 
Programming
List comprehensions (2.0) 
 Create lists without map(), 
filter(), lambda 
 = expression followed by for clause + 
zero or more for or of clauses 
>>> vec = [2,4,6] 
>>> [3*x for x in vec] 
[6, 12, 18] 
>>> [{x: x**2} for x in vec} 
[{2: 4}, {4: 16}, {6: 36}] 
Nov 6, 2014 Advanced 
Programming
List comprehensions 
 cross products: 
>>> vec1 = [2,4,6] 
>>> vec2 = [4,3,-9] 
>>> [x*y for x in vec1 for y in vec2] 
[8,6,-18, 16,12,-36, 24,18,-54] 
>>> [x+y for x in vec1 and y in vec2] 
[6,5,-7,8,7,-5,10,9,-3] 
>>> [vec1[i]*vec2[i] for i in 
range(len(vec1))] 
[8,12,-54] 
Nov 6, 2014 Advanced 
Programming
List comprehensions 
 can also use if: 
>>> [3*x for x in vec if x > 3] 
[12, 18] 
>>> [3*x for x in vec if x < 2] 
[] 
Nov 6, 2014 Advanced 
Programming
del – removing list items 
 remove by index, not value 
 remove slices from list (rather than by 
assigning an empty list) 
>>> a = [-1,1,66.6,333,333,1234.5] 
>>> del a[0] 
>>> a 
[1,66.6,333,333,1234.5] 
>>> del a[2:4] 
>>> a 
[1,66.6,1234.5] 
Nov 6, 2014 Advanced 
Programming
Tuples and sequences 
 lists, strings, tuples: examples of 
sequence type 
 tuple = values separated by commas 
>>> t = 123, 543, 'bar' 
>>> t[0] 
123 
>>> t 
(123, 543, 'bar') 
Nov 6, 2014 Advanced 
Programming
Tuples 
 Tuples may be nested 
>>> u = t, (1,2) 
>>> u 
((123, 542, 'bar'), (1,2)) 
 kind of like structs, but no element names: 
 (x,y) coordinates 
 database records 
 like strings, immutable  can't assign to 
individual items 
Nov 6, 2014 Advanced 
Programming
Tuples 
 Empty tuples: () 
>>> empty = () 
>>> len(empty) 
0 
 one item  trailing comma 
>>> singleton = 'foo', 
Nov 6, 2014 Advanced 
Programming
Tuples 
 sequence unpacking  distribute 
elements across variables 
>>> t = 123, 543, 'bar' 
>>> x, y, z = t 
>>> x 
123 
 packing always creates tuple 
 unpacking works for any sequence 
Nov 6, 2014 Advanced 
Programming
Dictionaries 
 like Tcl or awk associative arrays 
 indexed by keys 
 keys are any immutable type: e.g., tuples 
 but not lists (mutable!) 
 uses 'key: value' notation 
>>> tel = {'hgs' : 7042, 'lennox': 7018} 
>>> tel['cs'] = 7000 
>>> tel 
Nov 6, 2014 Advanced 
Programming
Dictionaries 
 no particular order 
 delete elements with del 
>>> del tel['foo'] 
 keys() method  unsorted list of keys 
>>> tel.keys() 
['cs', 'lennox', 'hgs'] 
 use has_key() to check for existence 
>>> tel.has_key('foo') 
0 
Nov 6, 2014 Advanced 
Programming
Conditions 
 can check for sequence membership with is 
and is not: 
>>> if (4 in vec): 
... print '4 is' 
 chained comparisons: a less than b AND b 
equals c: 
Nov 6, 2014 Advanced 
Programming 
a < b == c 
 and and or are short-circuit operators: 
 evaluated from left to right 
 stop evaluation as soon as outcome clear
Conditions 
 Can assign comparison to variable: 
>>> s1,s2,s3='', 'foo', 'bar' 
>>> non_null = s1 or s2 or s3 
>>> non_null 
foo 
 Unlike C, no assignment within 
expression 
Nov 6, 2014 Advanced 
Programming
Comparing sequences 
 unlike C, can compare sequences (lists, 
tuples, ...) 
 lexicographical comparison: 
 compare first; if different  outcome 
 continue recursively 
 subsequences are smaller 
 strings use ASCII comparison 
 can compare objects of different type, but 
by type name (list < string < tuple) 
Nov 6, 2014 Advanced 
Programming
Comparing sequences 
(1,2,3) < (1,2,4) 
[1,2,3] < [1,2,4] 
'ABC' < 'C' < 'Pascal' < 'Python' 
(1,2,3) == (1.0,2.0,3.0) 
(1,2) < (1,2,-1) 
Nov 6, 2014 Advanced 
Programming
Modules 
 collection of functions and variables, 
typically in scripts 
 definitions can be imported 
 file name is module name + .py 
 e.g., create module fibo.py 
def fib(n): # write Fib. series up to n 
... 
def fib2(n): # return Fib. series up to n 
Nov 6, 2014 Advanced 
Programming
Modules 
 import module: 
import fibo 
 Use modules via "name space": 
>>> fibo.fib(1000) 
>>> fibo.__name__ 
'fibo' 
 can give it a local name: 
>>> fib = fibo.fib 
>>> fib(500) 
Nov 6, 2014 Advanced 
Programming
Modules 
 function definition + executable statements 
 executed only when module is imported 
 modules have private symbol tables 
 avoids name clash for global variables 
 accessible as module.globalname 
 can import into name space: 
>>> from fibo import fib, fib2 
>>> fib(500) 
 can import all names defined by module: 
>>> from fibo import * 
Nov 6, 2014 Advanced 
Programming
Module search path 
 current directory 
 list of directories specified in PYTHONPATH 
environment variable 
 uses installation-default if not defined, e.g., 
.:/usr/local/lib/python 
 uses sys.path 
>>> import sys 
>>> sys.path 
['', 'C:PROGRA~1Python2.2', 'C:Program 
FilesPython2.2DLLs', 'C:Program 
FilesPython2.2lib', 'C:Program 
FilesPython2.2liblib-tk', 'C:Program 
FilesPython2.2', 'C:Program FilesPython2.2libsite-packages'] 
Nov 6, 2014 Advanced 
Programming
Compiled Python files 
 include byte-compiled version of module if 
there exists fibo.pyc in same directory as 
fibo.py 
 only if creation time of fibo.pyc matches 
fibo.py 
 automatically write compiled file, if possible 
 platform independent 
 doesn't run any faster, but loads faster 
 can have only .pyc file  hide source 
Nov 6, 2014 Advanced 
Programming
Standard modules 
 system-dependent list 
 always sys module 
>>> import sys 
>>> sys.p1 
'>>> ' 
>>> sys.p2 
'... ' 
>>> sys.path.append('/some/directory') 
Nov 6, 2014 Advanced 
Programming
Module listing 
 use dir() for each module 
>>> dir(fibo) 
['___name___', 'fib', 'fib2'] 
>>> dir(sys) 
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__stderr__', '__st 
din__', '__stdout__', '_getframe', 'argv', 'builtin_module_names', 'byteorder', 
'copyright', 'displayhook', 'dllhandle', 'exc_info', 'exc_type', 'excepthook', ' 
exec_prefix', 'executable', 'exit', 'getdefaultencoding', 'getrecursionlimit', ' 
getrefcount', 'hexversion', 'last_type', 'last_value', 'maxint', 'maxunicode', ' 
modules', 'path', 'platform', 'prefix', 'ps1', 'ps2', 'setcheckinterval', 'setpr 
ofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'version', 
'version_info', 'warnoptions', 'winver'] 
Nov 6, 2014 Advanced 
Programming
Classes 
 mixture of C++ and Modula-3 
 multiple base classes 
 derived class can override any methods of its 
base class(es) 
 method can call the method of a base class 
with the same name 
 objects have private data 
 C++ terms: 
 all class members are public 
 all member functions are virtual 
 no constructors or destructors (not needed) 
Nov 6, 2014 Advanced 
Programming
Classes 
 classes (and data types) are objects 
 built-in types cannot be used as base 
classes by user 
 arithmetic operators, subscripting can 
be redefined for class instances (like C+ 
+, unlike Java) 
Nov 6, 2014 Advanced 
Programming
Class definitions 
Class ClassName: 
<statement-1> 
... 
<statement-N> 
 must be executed 
 can be executed conditionally (see Tcl) 
 creates new namespace 
Nov 6, 2014 Advanced 
Programming
Namespaces 
 mapping from name to object: 
 built-in names (abs()) 
 global names in module 
 local names in function invocation 
 attributes = any following a dot 
 z.real, z.imag 
 attributes read-only or writable 
 module attributes are writeable 
Nov 6, 2014 Advanced 
Programming
Namespaces 
 scope = textual region of Python program 
where a namespace is directly accessible 
(without dot) 
 innermost scope (first) = local names 
 middle scope = current module's global names 
 outermost scope (last) = built-in names 
 assignments always affect innermost scope 
 don't copy, just create name bindings to objects 
 global indicates name is in global scope 
Nov 6, 2014 Advanced 
Programming
Class objects 
 obj.name references (plus module!): 
class MyClass: 
"A simple example class" 
i = 123 
def f(self): 
return 'hello world' 
>>> MyClass.i 
123 
 MyClass.f is method object 
Nov 6, 2014 Advanced 
Programming
Class objects 
 class instantiation: 
>>> x = MyClass() 
>>> x.f() 
'hello world' 
 creates new instance of class 
 note x = MyClass vs. x = MyClass() 
 ___init__() special method for 
initialization of object 
def __init__(self,realpart,imagpart): 
self.r = realpart 
self.i = imagpart 
Nov 6, 2014 Advanced 
Programming
Instance objects 
 attribute references 
 data attributes (C++/Java data 
members) 
 created dynamically 
x.counter = 1 
while x.counter < 10: 
x.counter = x.counter * 2 
print x.counter 
del x.counter 
Nov 6, 2014 Advanced 
Programming
Method objects 
 Called immediately: 
x.f() 
 can be referenced: 
Nov 6, 2014 Advanced 
Programming 
xf = x.f 
while 1: 
print xf() 
 object is passed as first argument of 
function  'self' 
 x.f() is equivalent to MyClass.f(x)
Notes on classes 
 Data attributes override method 
attributes with the same name 
 no real hiding  not usable to 
implement pure abstract data types 
 clients (users) of an object can add data 
attributes 
 first argument of method usually called 
self 
 'self' has no special meaning (cf. Java) 
Nov 6, 2014 Advanced 
Programming
Another example 
Nov 6, 2014 Advanced 
Programming 
 bag.py 
class Bag: 
def __init__(self): 
self.data = [] 
def add(self, x): 
self.data.append(x) 
def addtwice(self,x): 
self.add(x) 
self.add(x)
Another example, cont'd. 
Nov 6, 2014 Advanced 
Programming 
 invoke: 
>>> from bag import * 
>>> l = Bag() 
>>> l.add('first') 
>>> l.add('second') 
>>> l.data 
['first', 'second']
Inheritance 
class DerivedClassName(BaseClassName) 
<statement-1> 
... 
<statement-N> 
 search class attribute, descending 
chain of base classes 
 may override methods in the base class 
 call directly via BaseClassName.method 
Nov 6, 2014 Advanced 
Programming
Multiple inheritance 
class DerivedClass(Base1,Base2,Base3): 
<statement> 
 depth-first, left-to-right 
 problem: class derived from two classes 
with a common base class 
Nov 6, 2014 Advanced 
Programming
Private variables 
 No real support, but textual 
replacement (name mangling) 
 __var is replaced by 
_classname_var 
 prevents only accidental modification, 
not true protection 
Advanced 
Programming
~ C structs 
 Empty class definition: 
class Employee: 
pass 
john = Employee() 
john.name = 'John Doe' 
john.dept = 'CS' 
john.salary = 1000 
Advanced 
Programming
Exceptions 
 syntax (parsing) errors 
while 1 print 'Hello World' 
File "<stdin>", line 1 
while 1 print 'Hello World' 
^ 
SyntaxError: invalid syntax 
 exceptions 
 run-time errors 
 e.g., ZeroDivisionError, 
NameError, TypeError 
Nov 6, 2014 Advanced 
Programming
Handling exceptions 
Nov 6, 2014 Advanced 
Programming 
while 1: 
try: 
x = int(raw_input("Please enter a number: ")) 
break 
except ValueError: 
print "Not a valid number" 
 First, execute try clause 
 if no exception, skip except clause 
 if exception, skip rest of try clause and use except 
clause 
 if no matching exception, attempt outer try 
statement
Handling exceptions 
 try.py 
import sys 
for arg in sys.argv[1:]: 
try: 
f = open(arg, 'r') 
except IOError: 
print 'cannot open', arg 
else: 
print arg, 'lines:', len(f.readlines()) 
f.close 
 e.g., as python try.py *.py
Language comparison 
Tcl Perl Python JavaScript Visual 
Basic 
Speed development      
regexp    
breadth extensible    
embeddable   
easy GUI   (Tk)  
net/web      
enterprise cross-platform     
I18N     
thread-safe    
database access     
Thank You !!!

More Related Content

What's hot

Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real World
osfameron
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimizationg3_nittala
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance Python
Ian Ozsvald
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
Jonas Bonér
 
Statistical computing 01
Statistical computing 01Statistical computing 01
Statistical computing 01
Kevin Chun-Hsien Hsu
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
Wei-Yuan Chang
 
Recursion schemes in Scala
Recursion schemes in ScalaRecursion schemes in Scala
Recursion schemes in Scala
Arthur Kushka
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge
O T
 
R intro 20140716-advance
R intro 20140716-advanceR intro 20140716-advance
R intro 20140716-advance
Kevin Chun-Hsien Hsu
 
Odessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and PythonOdessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and Python
Max Klymyshyn
 
Learn python in 20 minutes
Learn python in 20 minutesLearn python in 20 minutes
Learn python in 20 minutes
Sidharth Nadhan
 
Fun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming languageFun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming language
Pawel Szulc
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
Denis
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! aleks-f
 
HPX: C++11 runtime система для параллельных и распределённых вычислений
HPX: C++11 runtime система для параллельных и распределённых вычисленийHPX: C++11 runtime система для параллельных и распределённых вычислений
HPX: C++11 runtime система для параллельных и распределённых вычислений
Platonov Sergey
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
intelliyole
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meetMario Fusco
 
Alex Smola at AI Frontiers: Scalable Deep Learning Using MXNet
Alex Smola at AI Frontiers: Scalable Deep Learning Using MXNetAlex Smola at AI Frontiers: Scalable Deep Learning Using MXNet
Alex Smola at AI Frontiers: Scalable Deep Learning Using MXNet
AI Frontiers
 
Scala introduction
Scala introductionScala introduction
Scala introduction
vito jeng
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
BTI360
 

What's hot (20)

Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real World
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance Python
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
Statistical computing 01
Statistical computing 01Statistical computing 01
Statistical computing 01
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
 
Recursion schemes in Scala
Recursion schemes in ScalaRecursion schemes in Scala
Recursion schemes in Scala
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge
 
R intro 20140716-advance
R intro 20140716-advanceR intro 20140716-advance
R intro 20140716-advance
 
Odessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and PythonOdessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and Python
 
Learn python in 20 minutes
Learn python in 20 minutesLearn python in 20 minutes
Learn python in 20 minutes
 
Fun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming languageFun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming language
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! 
 
HPX: C++11 runtime система для параллельных и распределённых вычислений
HPX: C++11 runtime система для параллельных и распределённых вычисленийHPX: C++11 runtime система для параллельных и распределённых вычислений
HPX: C++11 runtime система для параллельных и распределённых вычислений
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
Alex Smola at AI Frontiers: Scalable Deep Learning Using MXNet
Alex Smola at AI Frontiers: Scalable Deep Learning Using MXNetAlex Smola at AI Frontiers: Scalable Deep Learning Using MXNet
Alex Smola at AI Frontiers: Scalable Deep Learning Using MXNet
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 

Viewers also liked

Python Programming - V. Sequences (List and Tuples) and Dictionaries
Python Programming - V. Sequences (List and Tuples) and DictionariesPython Programming - V. Sequences (List and Tuples) and Dictionaries
Python Programming - V. Sequences (List and Tuples) and Dictionaries
Ranel Padon
 
Robotics classes in mumbai
Robotics classes in mumbaiRobotics classes in mumbai
Robotics classes in mumbai
Vibrant Technologies & Computers
 
How Fannie Mae Leverages Data Quality to Improve the Business
How Fannie Mae Leverages Data Quality to Improve the BusinessHow Fannie Mae Leverages Data Quality to Improve the Business
How Fannie Mae Leverages Data Quality to Improve the Business
DLT Solutions
 
Robotics training in mumbai
Robotics training in mumbai Robotics training in mumbai
Robotics training in mumbai
Vibrant Technologies & Computers
 
How to Accelerate Backup Performance with Dell DR Series Backup Appliances
How to Accelerate Backup Performance with Dell DR Series Backup AppliancesHow to Accelerate Backup Performance with Dell DR Series Backup Appliances
How to Accelerate Backup Performance with Dell DR Series Backup Appliances
DLT Solutions
 
High Dimensional Indexing using MongoDB (MongoSV 2012)
High Dimensional Indexing using MongoDB (MongoSV 2012)High Dimensional Indexing using MongoDB (MongoSV 2012)
High Dimensional Indexing using MongoDB (MongoSV 2012)Nicholas Knize, Ph.D., GISP
 
Cloud Ready Data: Speeding Your Journey to the Cloud
Cloud Ready Data: Speeding Your Journey to the CloudCloud Ready Data: Speeding Your Journey to the Cloud
Cloud Ready Data: Speeding Your Journey to the Cloud
DLT Solutions
 
Business Innovation Approach
Business Innovation ApproachBusiness Innovation Approach
Business Innovation Approach
Koen Klokgieters
 
Developer's Guide to Knights Landing
Developer's Guide to Knights LandingDeveloper's Guide to Knights Landing
Developer's Guide to Knights Landing
Andrey Vladimirov
 
Reduce Networking/Infrastructure Cost With Multi-Vendor Equipment and Support...
Reduce Networking/Infrastructure Cost With Multi-Vendor Equipment and Support...Reduce Networking/Infrastructure Cost With Multi-Vendor Equipment and Support...
Reduce Networking/Infrastructure Cost With Multi-Vendor Equipment and Support...
Curvature
 
Dematic Logistics Review #5
Dematic Logistics Review #5Dematic Logistics Review #5
Dematic Logistics Review #5
scottcottingham
 
PCB DESIGN - Introduction to PCB Design Manufacturing
PCB DESIGN - Introduction to PCB Design ManufacturingPCB DESIGN - Introduction to PCB Design Manufacturing
PCB DESIGN - Introduction to PCB Design Manufacturing
Vibrant Technologies & Computers
 
Market Intelligence FY15 Defense Budget Briefing
 Market Intelligence FY15 Defense Budget Briefing Market Intelligence FY15 Defense Budget Briefing
Market Intelligence FY15 Defense Budget Briefing
immixGroup
 
Lecture 8Cylinders & open and closed circuit
Lecture 8Cylinders & open and closed circuitLecture 8Cylinders & open and closed circuit
Lecture 8Cylinders & open and closed circuitJavaid Toosy
 
Revisions in the new d1.1 2010
Revisions in the new d1.1 2010Revisions in the new d1.1 2010
Revisions in the new d1.1 2010ruilong9
 
VVTA: RFP 2015-03: CNG Fuel Cylinder Replacement
VVTA: RFP 2015-03: CNG Fuel Cylinder ReplacementVVTA: RFP 2015-03: CNG Fuel Cylinder Replacement
VVTA: RFP 2015-03: CNG Fuel Cylinder Replacement
Victor Valley Transit Authority
 
SDN Security: Two Sides of the Same Coin
SDN Security: Two Sides of the Same CoinSDN Security: Two Sides of the Same Coin
SDN Security: Two Sides of the Same Coin
Zivaro Inc
 
Insider Threat Solution from GTRI
Insider Threat Solution from GTRIInsider Threat Solution from GTRI
Insider Threat Solution from GTRI
Zivaro Inc
 
Railway training report
Railway training reportRailway training report
Railway training report
Deepak kango
 
As9100 interpretations
As9100 interpretationsAs9100 interpretations
As9100 interpretations
oziel2015
 

Viewers also liked (20)

Python Programming - V. Sequences (List and Tuples) and Dictionaries
Python Programming - V. Sequences (List and Tuples) and DictionariesPython Programming - V. Sequences (List and Tuples) and Dictionaries
Python Programming - V. Sequences (List and Tuples) and Dictionaries
 
Robotics classes in mumbai
Robotics classes in mumbaiRobotics classes in mumbai
Robotics classes in mumbai
 
How Fannie Mae Leverages Data Quality to Improve the Business
How Fannie Mae Leverages Data Quality to Improve the BusinessHow Fannie Mae Leverages Data Quality to Improve the Business
How Fannie Mae Leverages Data Quality to Improve the Business
 
Robotics training in mumbai
Robotics training in mumbai Robotics training in mumbai
Robotics training in mumbai
 
How to Accelerate Backup Performance with Dell DR Series Backup Appliances
How to Accelerate Backup Performance with Dell DR Series Backup AppliancesHow to Accelerate Backup Performance with Dell DR Series Backup Appliances
How to Accelerate Backup Performance with Dell DR Series Backup Appliances
 
High Dimensional Indexing using MongoDB (MongoSV 2012)
High Dimensional Indexing using MongoDB (MongoSV 2012)High Dimensional Indexing using MongoDB (MongoSV 2012)
High Dimensional Indexing using MongoDB (MongoSV 2012)
 
Cloud Ready Data: Speeding Your Journey to the Cloud
Cloud Ready Data: Speeding Your Journey to the CloudCloud Ready Data: Speeding Your Journey to the Cloud
Cloud Ready Data: Speeding Your Journey to the Cloud
 
Business Innovation Approach
Business Innovation ApproachBusiness Innovation Approach
Business Innovation Approach
 
Developer's Guide to Knights Landing
Developer's Guide to Knights LandingDeveloper's Guide to Knights Landing
Developer's Guide to Knights Landing
 
Reduce Networking/Infrastructure Cost With Multi-Vendor Equipment and Support...
Reduce Networking/Infrastructure Cost With Multi-Vendor Equipment and Support...Reduce Networking/Infrastructure Cost With Multi-Vendor Equipment and Support...
Reduce Networking/Infrastructure Cost With Multi-Vendor Equipment and Support...
 
Dematic Logistics Review #5
Dematic Logistics Review #5Dematic Logistics Review #5
Dematic Logistics Review #5
 
PCB DESIGN - Introduction to PCB Design Manufacturing
PCB DESIGN - Introduction to PCB Design ManufacturingPCB DESIGN - Introduction to PCB Design Manufacturing
PCB DESIGN - Introduction to PCB Design Manufacturing
 
Market Intelligence FY15 Defense Budget Briefing
 Market Intelligence FY15 Defense Budget Briefing Market Intelligence FY15 Defense Budget Briefing
Market Intelligence FY15 Defense Budget Briefing
 
Lecture 8Cylinders & open and closed circuit
Lecture 8Cylinders & open and closed circuitLecture 8Cylinders & open and closed circuit
Lecture 8Cylinders & open and closed circuit
 
Revisions in the new d1.1 2010
Revisions in the new d1.1 2010Revisions in the new d1.1 2010
Revisions in the new d1.1 2010
 
VVTA: RFP 2015-03: CNG Fuel Cylinder Replacement
VVTA: RFP 2015-03: CNG Fuel Cylinder ReplacementVVTA: RFP 2015-03: CNG Fuel Cylinder Replacement
VVTA: RFP 2015-03: CNG Fuel Cylinder Replacement
 
SDN Security: Two Sides of the Same Coin
SDN Security: Two Sides of the Same CoinSDN Security: Two Sides of the Same Coin
SDN Security: Two Sides of the Same Coin
 
Insider Threat Solution from GTRI
Insider Threat Solution from GTRIInsider Threat Solution from GTRI
Insider Threat Solution from GTRI
 
Railway training report
Railway training reportRailway training report
Railway training report
 
As9100 interpretations
As9100 interpretationsAs9100 interpretations
As9100 interpretations
 

Similar to Python classes in mumbai

sonam Kumari python.ppt
sonam Kumari python.pptsonam Kumari python.ppt
sonam Kumari python.ppt
ssuserd64918
 
Python basics - for bigginers
Python basics - for bigginersPython basics - for bigginers
Python basics - for bigginers
Abdulaziz M. Ghaleb
 
python.ppt
python.pptpython.ppt
python.ppt
ramamoorthi24
 
python presentation lists,strings,operation
python presentation lists,strings,operationpython presentation lists,strings,operation
python presentation lists,strings,operation
ManjuRaghavan1
 
python.ppt
python.pptpython.ppt
python.ppt
Arun471829
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
Python basics
Python basicsPython basics
Python basics
PrafullaKamble3
 
python.ppt
python.pptpython.ppt
python.ppt
MukundSharma74
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
rik0
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
PyCon Italia
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slide
jonycse
 
python.ppt
python.pptpython.ppt
python.ppt
MayankRai689616
 
Python in 90mins
Python in 90minsPython in 90mins
Python in 90mins
Larry Cai
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
decoupled
 
python.ppt
python.pptpython.ppt
python.ppt
HighVoltage8
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
Guy Lebanon
 
python(1).ppt
python(1).pptpython(1).ppt
python(1).ppt
hamm14
 
python.ppt
python.pptpython.ppt
python.ppt
NikhilSoni177492
 

Similar to Python classes in mumbai (20)

sonam Kumari python.ppt
sonam Kumari python.pptsonam Kumari python.ppt
sonam Kumari python.ppt
 
python.ppt
python.pptpython.ppt
python.ppt
 
Python basics - for bigginers
Python basics - for bigginersPython basics - for bigginers
Python basics - for bigginers
 
python.ppt
python.pptpython.ppt
python.ppt
 
python presentation lists,strings,operation
python presentation lists,strings,operationpython presentation lists,strings,operation
python presentation lists,strings,operation
 
python.ppt
python.pptpython.ppt
python.ppt
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Python basics
Python basicsPython basics
Python basics
 
python.ppt
python.pptpython.ppt
python.ppt
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slide
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
python.ppt
python.pptpython.ppt
python.ppt
 
Python in 90mins
Python in 90minsPython in 90mins
Python in 90mins
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
python.ppt
python.pptpython.ppt
python.ppt
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
 
python(1).ppt
python(1).pptpython(1).ppt
python(1).ppt
 
python.ppt
python.pptpython.ppt
python.ppt
 

More from Vibrant Technologies & Computers

Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5
Vibrant Technologies & Computers
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
Vibrant Technologies & Computers
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
Vibrant Technologies & Computers
 
SQL- Introduction to SQL database
SQL- Introduction to SQL database SQL- Introduction to SQL database
SQL- Introduction to SQL database
Vibrant Technologies & Computers
 
ITIL - introduction to ITIL
ITIL - introduction to ITILITIL - introduction to ITIL
ITIL - introduction to ITIL
Vibrant Technologies & Computers
 
Salesforce - Introduction to Security & Access
Salesforce -  Introduction to Security & Access Salesforce -  Introduction to Security & Access
Salesforce - Introduction to Security & Access
Vibrant Technologies & Computers
 
Data ware housing- Introduction to olap .
Data ware housing- Introduction to  olap .Data ware housing- Introduction to  olap .
Data ware housing- Introduction to olap .
Vibrant Technologies & Computers
 
Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.
Vibrant Technologies & Computers
 
Data ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housingData ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housing
Vibrant Technologies & Computers
 
Salesforce - classification of cloud computing
Salesforce - classification of cloud computingSalesforce - classification of cloud computing
Salesforce - classification of cloud computing
Vibrant Technologies & Computers
 
Salesforce - cloud computing fundamental
Salesforce - cloud computing fundamentalSalesforce - cloud computing fundamental
Salesforce - cloud computing fundamental
Vibrant Technologies & Computers
 
SQL- Introduction to PL/SQL
SQL- Introduction to  PL/SQLSQL- Introduction to  PL/SQL
SQL- Introduction to PL/SQL
Vibrant Technologies & Computers
 
SQL- Introduction to advanced sql concepts
SQL- Introduction to  advanced sql conceptsSQL- Introduction to  advanced sql concepts
SQL- Introduction to advanced sql concepts
Vibrant Technologies & Computers
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
Vibrant Technologies & Computers
 
SQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set OperationsSQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set Operations
Vibrant Technologies & Computers
 
Sas - Introduction to designing the data mart
Sas - Introduction to designing the data martSas - Introduction to designing the data mart
Sas - Introduction to designing the data mart
Vibrant Technologies & Computers
 
Sas - Introduction to working under change management
Sas - Introduction to working under change managementSas - Introduction to working under change management
Sas - Introduction to working under change management
Vibrant Technologies & Computers
 
SAS - overview of SAS
SAS - overview of SASSAS - overview of SAS
SAS - overview of SAS
Vibrant Technologies & Computers
 
Teradata - Architecture of Teradata
Teradata - Architecture of TeradataTeradata - Architecture of Teradata
Teradata - Architecture of Teradata
Vibrant Technologies & Computers
 
Teradata - Restoring Data
Teradata - Restoring Data Teradata - Restoring Data
Teradata - Restoring Data
Vibrant Technologies & Computers
 

More from Vibrant Technologies & Computers (20)

Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
 
SQL- Introduction to SQL database
SQL- Introduction to SQL database SQL- Introduction to SQL database
SQL- Introduction to SQL database
 
ITIL - introduction to ITIL
ITIL - introduction to ITILITIL - introduction to ITIL
ITIL - introduction to ITIL
 
Salesforce - Introduction to Security & Access
Salesforce -  Introduction to Security & Access Salesforce -  Introduction to Security & Access
Salesforce - Introduction to Security & Access
 
Data ware housing- Introduction to olap .
Data ware housing- Introduction to  olap .Data ware housing- Introduction to  olap .
Data ware housing- Introduction to olap .
 
Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.
 
Data ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housingData ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housing
 
Salesforce - classification of cloud computing
Salesforce - classification of cloud computingSalesforce - classification of cloud computing
Salesforce - classification of cloud computing
 
Salesforce - cloud computing fundamental
Salesforce - cloud computing fundamentalSalesforce - cloud computing fundamental
Salesforce - cloud computing fundamental
 
SQL- Introduction to PL/SQL
SQL- Introduction to  PL/SQLSQL- Introduction to  PL/SQL
SQL- Introduction to PL/SQL
 
SQL- Introduction to advanced sql concepts
SQL- Introduction to  advanced sql conceptsSQL- Introduction to  advanced sql concepts
SQL- Introduction to advanced sql concepts
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
SQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set OperationsSQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set Operations
 
Sas - Introduction to designing the data mart
Sas - Introduction to designing the data martSas - Introduction to designing the data mart
Sas - Introduction to designing the data mart
 
Sas - Introduction to working under change management
Sas - Introduction to working under change managementSas - Introduction to working under change management
Sas - Introduction to working under change management
 
SAS - overview of SAS
SAS - overview of SASSAS - overview of SAS
SAS - overview of SAS
 
Teradata - Architecture of Teradata
Teradata - Architecture of TeradataTeradata - Architecture of Teradata
Teradata - Architecture of Teradata
 
Teradata - Restoring Data
Teradata - Restoring Data Teradata - Restoring Data
Teradata - Restoring Data
 

Recently uploaded

Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Ashish Kohli
 
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
NelTorrente
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
MERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDFMERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDF
scholarhattraining
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Reflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPointReflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPoint
amberjdewit93
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 

Recently uploaded (20)

Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
 
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
MERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDFMERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDF
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Reflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPointReflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPoint
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 

Python classes in mumbai

  • 2. Python By AAddddrreessss:: KK11// 44,, SSeeccoonndd fflloooorr,, SSeeccttoorr--1155//1166 MMaarrkkeett,, VVaasshhii,, NNaavvii MMuummbbaaii MMoobb NNoo:: 99889922990000110033 99889922990000117733
  • 3. Introduction  Most recent popular (scripting/extension) language  although origin ~1991  heritage: teaching language (ABC)  Tcl: shell  perl: string (regex) processing  object-oriented  rather than add-on (OOTcl)
  • 4. Python philosophy  Coherence  not hard to read, write and maintain  power  scope  rapid development + large systems  objects  integration  hybrid systems
  • 5. Python features no compiling or linking rapid development cycle no type declarations simpler, shorter, more flexible automatic memory management garbage collection high-level data types and operations object-oriented programming code structuring and reuse, C++ embedding and extending in C mixed language systems classes, modules, exceptions "programming-in-the-large" support dynamic loading of C modules simplified extensions, smaller dynamic reloading of C modules programs can be modified without Nov 6, 2014 Advanced fast development binaries stopping Programming Lutz, Programming Python
  • 6. Python features Lutz, Programming Python universal "first-class" object model fewer restrictions and rules run-time program construction handles unforeseen needs, end-user coding interactive, dynamic nature incremental development and testing access to interpreter information metaprogramming, introspective objects wide portability cross-platform programming without ports compilation to portable byte-code execution speed, protecting source code built-in interfaces to external services system tools, GUIs, persistence, databases, etc.
  • 7. Python  elements from C++, Modula-3 (modules), ABC, Icon (slicing)  same family as Perl, Tcl, Scheme, REXX, BASIC dialects Nov 6, 2014 Advanced Programming
  • 8. Uses of Python Advanced Programming  shell tools  system admin tools, command line programs  extension-language work  rapid prototyping and development  language-based modules  instead of special-purpose parsers  graphical user interfaces  database access  distributed programming  Internet scripting
  • 9. What not to use Python (and kin) for  most scripting languages share these  not as efficient as C  but sometimes better built-in algorithms (e.g., hashing and sorting)  delayed error notification  lack of profiling tools Nov 6, 2014 Advanced Programming
  • 10. Using python  /usr/local/bin/python  #! /usr/bin/env python  interactive use Python 1.6 (#1, Sep 24 2000, 20:40:45) [GCC 2.95.1 19990816 (release)] on sunos5 Copyright (c) 1995-2000 Corporation for National Research Initiatives. All Rights Reserved. Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam. All Rights Reserved. >>>  python –c command [arg] ...  python –i script  read script first, then interactive Nov 6, 2014 Advanced Programming
  • 11. Python structure  modules: Python source files or C extensions  import, top-level via from, reload Advanced Programming  statements  control flow  create objects  indentation matters – instead of {}  objects  everything is an object  automatically reclaimed when no longer needed
  • 12. First example #!/usr/local/bin/python # import systems module import sys marker = '::::::' for name in sys.argv[1:]: input = open(name, 'r') print marker + name print input.read() Nov 6, 2014 Advanced Programming
  • 13. Basic operations Nov 6, 2014 Advanced Programming  Assignment:  size = 40  a = b = c = 3  Numbers  integer, float  complex numbers: 1j+3, abs(z)  Strings  'hello world', 'it's hot'  "bye world"  continuation via or use """ long text """"
  • 14. String operations  concatenate with + or neighbors  word = 'Help' + x  word = 'Help' 'a'  subscripting of strings  'Hello'[2]  'l'  slice: 'Hello'[1:2]  'el'  word[-1]  last character  len(word)  5  immutable: cannot assign to subscript Advanced Programming
  • 15. Lists  lists can be heterogeneous  a = ['spam', 'eggs', 100, 1234, 2*2]  Lists can be indexed and sliced:  a[0]  spam  a[:2]  ['spam', 'eggs']  Lists can be manipulated  a[2] = a[2] + 23  a[0:2] = [1,12]  a[0:0] = []  len(a)  5 Nov 6, 2014 Advanced Programming
  • 16. Basic programming a,b = 0, 1 # non-zero = true while b < 10: # formatted output, without n print b, # multiple assignment a,b = b, a+b Nov 6, 2014 Advanced Programming
  • 17. Control flow: if x = int(raw_input("Please enter #:")) if x < 0: x = 0 print 'Negative changed to zero' Nov 6, 2014 Advanced Programming elif x == 0: print 'Zero' elif x == 1: print 'Single' else: print 'More'  no case statement
  • 18. Control flow: for a = ['cat', 'window', 'defenestrate'] for x in a: print x, len(x)  no arithmetic progression, but  range(10)  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]  for i in range(len(a)): print i, a[i]  do not modify the sequence being iterated over Nov 6, 2014 Advanced Programming
  • 19. Loops: break, continue, else  break and continue like C  else after loop exhaustion for n in range(2,10): for x in range(2,n): if n % x == 0: print n, 'equals', x, '*', n/x break Nov 6, 2014 Advanced Programming else: # loop fell through without finding a factor print n, 'is prime'
  • 20. Do nothing  pass does nothing  syntactic filler while 1: Advanced Programming pass
  • 21. Defining functions Nov 6, 2014 Advanced Programming def fib(n): """Print a Fibonacci series up to n.""" a, b = 0, 1 while b < n: print b, a, b = b, a+b >>> fib(2000)  First line is docstring  first look for variables in local, then global  need global to assign global variables
  • 22. Functions: default argument values def ask_ok(prompt, retries=4, complaint='Yes or no, please!'): Nov 6, 2014 Advanced Programming while 1: ok = raw_input(prompt) if ok in ('y', 'ye', 'yes'): return 1 if ok in ('n', 'no'): return 0 retries = retries - 1 if retries < 0: raise IOError, 'refusenik error' print complaint >>> ask_ok('Really?')
  • 23. Keyword arguments  last arguments can be given as keywords def parrot(voltage, state='a stiff', action='voom', type='Norwegian blue'): print "-- This parrot wouldn't", action, print "if you put", voltage, "Volts through it." print "Lovely plumage, the ", type print "-- It's", state, "!" parrot(1000) parrot(action='VOOOM', voltage=100000) Nov 6, 2014 Advanced Programming
  • 24. Lambda forms  anonymous functions  may not work in older versions def make_incrementor(n): return lambda x: x + n f = make_incrementor(42) f(0) f(1) Advanced Programming
  • 25. List methods Nov 6, 2014 Advanced Programming  append(x)  extend(L)  append all items in list (like Tcl lappend)  insert(i,x)  remove(x)  pop([i]), pop()  create stack (FIFO), or queue (LIFO)  pop(0)  index(x)  return the index for value x
  • 26. List methods Nov 6, 2014 Advanced Programming  count(x)  how many times x appears in list  sort()  sort items in place  reverse()  reverse list
  • 27. Functional programming tools  filter(function, sequence) def f(x): return x%2 != 0 and x%3 0 filter(f, range(2,25))  map(function, sequence)  call function for each item  return list of return values  reduce(function, sequence)  return a single value  call binary function on the first two items  then on the result and next item  iterate Nov 6, 2014 Advanced Programming
  • 28. List comprehensions (2.0)  Create lists without map(), filter(), lambda  = expression followed by for clause + zero or more for or of clauses >>> vec = [2,4,6] >>> [3*x for x in vec] [6, 12, 18] >>> [{x: x**2} for x in vec} [{2: 4}, {4: 16}, {6: 36}] Nov 6, 2014 Advanced Programming
  • 29. List comprehensions  cross products: >>> vec1 = [2,4,6] >>> vec2 = [4,3,-9] >>> [x*y for x in vec1 for y in vec2] [8,6,-18, 16,12,-36, 24,18,-54] >>> [x+y for x in vec1 and y in vec2] [6,5,-7,8,7,-5,10,9,-3] >>> [vec1[i]*vec2[i] for i in range(len(vec1))] [8,12,-54] Nov 6, 2014 Advanced Programming
  • 30. List comprehensions  can also use if: >>> [3*x for x in vec if x > 3] [12, 18] >>> [3*x for x in vec if x < 2] [] Nov 6, 2014 Advanced Programming
  • 31. del – removing list items  remove by index, not value  remove slices from list (rather than by assigning an empty list) >>> a = [-1,1,66.6,333,333,1234.5] >>> del a[0] >>> a [1,66.6,333,333,1234.5] >>> del a[2:4] >>> a [1,66.6,1234.5] Nov 6, 2014 Advanced Programming
  • 32. Tuples and sequences  lists, strings, tuples: examples of sequence type  tuple = values separated by commas >>> t = 123, 543, 'bar' >>> t[0] 123 >>> t (123, 543, 'bar') Nov 6, 2014 Advanced Programming
  • 33. Tuples  Tuples may be nested >>> u = t, (1,2) >>> u ((123, 542, 'bar'), (1,2))  kind of like structs, but no element names:  (x,y) coordinates  database records  like strings, immutable  can't assign to individual items Nov 6, 2014 Advanced Programming
  • 34. Tuples  Empty tuples: () >>> empty = () >>> len(empty) 0  one item  trailing comma >>> singleton = 'foo', Nov 6, 2014 Advanced Programming
  • 35. Tuples  sequence unpacking  distribute elements across variables >>> t = 123, 543, 'bar' >>> x, y, z = t >>> x 123  packing always creates tuple  unpacking works for any sequence Nov 6, 2014 Advanced Programming
  • 36. Dictionaries  like Tcl or awk associative arrays  indexed by keys  keys are any immutable type: e.g., tuples  but not lists (mutable!)  uses 'key: value' notation >>> tel = {'hgs' : 7042, 'lennox': 7018} >>> tel['cs'] = 7000 >>> tel Nov 6, 2014 Advanced Programming
  • 37. Dictionaries  no particular order  delete elements with del >>> del tel['foo']  keys() method  unsorted list of keys >>> tel.keys() ['cs', 'lennox', 'hgs']  use has_key() to check for existence >>> tel.has_key('foo') 0 Nov 6, 2014 Advanced Programming
  • 38. Conditions  can check for sequence membership with is and is not: >>> if (4 in vec): ... print '4 is'  chained comparisons: a less than b AND b equals c: Nov 6, 2014 Advanced Programming a < b == c  and and or are short-circuit operators:  evaluated from left to right  stop evaluation as soon as outcome clear
  • 39. Conditions  Can assign comparison to variable: >>> s1,s2,s3='', 'foo', 'bar' >>> non_null = s1 or s2 or s3 >>> non_null foo  Unlike C, no assignment within expression Nov 6, 2014 Advanced Programming
  • 40. Comparing sequences  unlike C, can compare sequences (lists, tuples, ...)  lexicographical comparison:  compare first; if different  outcome  continue recursively  subsequences are smaller  strings use ASCII comparison  can compare objects of different type, but by type name (list < string < tuple) Nov 6, 2014 Advanced Programming
  • 41. Comparing sequences (1,2,3) < (1,2,4) [1,2,3] < [1,2,4] 'ABC' < 'C' < 'Pascal' < 'Python' (1,2,3) == (1.0,2.0,3.0) (1,2) < (1,2,-1) Nov 6, 2014 Advanced Programming
  • 42. Modules  collection of functions and variables, typically in scripts  definitions can be imported  file name is module name + .py  e.g., create module fibo.py def fib(n): # write Fib. series up to n ... def fib2(n): # return Fib. series up to n Nov 6, 2014 Advanced Programming
  • 43. Modules  import module: import fibo  Use modules via "name space": >>> fibo.fib(1000) >>> fibo.__name__ 'fibo'  can give it a local name: >>> fib = fibo.fib >>> fib(500) Nov 6, 2014 Advanced Programming
  • 44. Modules  function definition + executable statements  executed only when module is imported  modules have private symbol tables  avoids name clash for global variables  accessible as module.globalname  can import into name space: >>> from fibo import fib, fib2 >>> fib(500)  can import all names defined by module: >>> from fibo import * Nov 6, 2014 Advanced Programming
  • 45. Module search path  current directory  list of directories specified in PYTHONPATH environment variable  uses installation-default if not defined, e.g., .:/usr/local/lib/python  uses sys.path >>> import sys >>> sys.path ['', 'C:PROGRA~1Python2.2', 'C:Program FilesPython2.2DLLs', 'C:Program FilesPython2.2lib', 'C:Program FilesPython2.2liblib-tk', 'C:Program FilesPython2.2', 'C:Program FilesPython2.2libsite-packages'] Nov 6, 2014 Advanced Programming
  • 46. Compiled Python files  include byte-compiled version of module if there exists fibo.pyc in same directory as fibo.py  only if creation time of fibo.pyc matches fibo.py  automatically write compiled file, if possible  platform independent  doesn't run any faster, but loads faster  can have only .pyc file  hide source Nov 6, 2014 Advanced Programming
  • 47. Standard modules  system-dependent list  always sys module >>> import sys >>> sys.p1 '>>> ' >>> sys.p2 '... ' >>> sys.path.append('/some/directory') Nov 6, 2014 Advanced Programming
  • 48. Module listing  use dir() for each module >>> dir(fibo) ['___name___', 'fib', 'fib2'] >>> dir(sys) ['__displayhook__', '__doc__', '__excepthook__', '__name__', '__stderr__', '__st din__', '__stdout__', '_getframe', 'argv', 'builtin_module_names', 'byteorder', 'copyright', 'displayhook', 'dllhandle', 'exc_info', 'exc_type', 'excepthook', ' exec_prefix', 'executable', 'exit', 'getdefaultencoding', 'getrecursionlimit', ' getrefcount', 'hexversion', 'last_type', 'last_value', 'maxint', 'maxunicode', ' modules', 'path', 'platform', 'prefix', 'ps1', 'ps2', 'setcheckinterval', 'setpr ofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'version', 'version_info', 'warnoptions', 'winver'] Nov 6, 2014 Advanced Programming
  • 49. Classes  mixture of C++ and Modula-3  multiple base classes  derived class can override any methods of its base class(es)  method can call the method of a base class with the same name  objects have private data  C++ terms:  all class members are public  all member functions are virtual  no constructors or destructors (not needed) Nov 6, 2014 Advanced Programming
  • 50. Classes  classes (and data types) are objects  built-in types cannot be used as base classes by user  arithmetic operators, subscripting can be redefined for class instances (like C+ +, unlike Java) Nov 6, 2014 Advanced Programming
  • 51. Class definitions Class ClassName: <statement-1> ... <statement-N>  must be executed  can be executed conditionally (see Tcl)  creates new namespace Nov 6, 2014 Advanced Programming
  • 52. Namespaces  mapping from name to object:  built-in names (abs())  global names in module  local names in function invocation  attributes = any following a dot  z.real, z.imag  attributes read-only or writable  module attributes are writeable Nov 6, 2014 Advanced Programming
  • 53. Namespaces  scope = textual region of Python program where a namespace is directly accessible (without dot)  innermost scope (first) = local names  middle scope = current module's global names  outermost scope (last) = built-in names  assignments always affect innermost scope  don't copy, just create name bindings to objects  global indicates name is in global scope Nov 6, 2014 Advanced Programming
  • 54. Class objects  obj.name references (plus module!): class MyClass: "A simple example class" i = 123 def f(self): return 'hello world' >>> MyClass.i 123  MyClass.f is method object Nov 6, 2014 Advanced Programming
  • 55. Class objects  class instantiation: >>> x = MyClass() >>> x.f() 'hello world'  creates new instance of class  note x = MyClass vs. x = MyClass()  ___init__() special method for initialization of object def __init__(self,realpart,imagpart): self.r = realpart self.i = imagpart Nov 6, 2014 Advanced Programming
  • 56. Instance objects  attribute references  data attributes (C++/Java data members)  created dynamically x.counter = 1 while x.counter < 10: x.counter = x.counter * 2 print x.counter del x.counter Nov 6, 2014 Advanced Programming
  • 57. Method objects  Called immediately: x.f()  can be referenced: Nov 6, 2014 Advanced Programming xf = x.f while 1: print xf()  object is passed as first argument of function  'self'  x.f() is equivalent to MyClass.f(x)
  • 58. Notes on classes  Data attributes override method attributes with the same name  no real hiding  not usable to implement pure abstract data types  clients (users) of an object can add data attributes  first argument of method usually called self  'self' has no special meaning (cf. Java) Nov 6, 2014 Advanced Programming
  • 59. Another example Nov 6, 2014 Advanced Programming  bag.py class Bag: def __init__(self): self.data = [] def add(self, x): self.data.append(x) def addtwice(self,x): self.add(x) self.add(x)
  • 60. Another example, cont'd. Nov 6, 2014 Advanced Programming  invoke: >>> from bag import * >>> l = Bag() >>> l.add('first') >>> l.add('second') >>> l.data ['first', 'second']
  • 61. Inheritance class DerivedClassName(BaseClassName) <statement-1> ... <statement-N>  search class attribute, descending chain of base classes  may override methods in the base class  call directly via BaseClassName.method Nov 6, 2014 Advanced Programming
  • 62. Multiple inheritance class DerivedClass(Base1,Base2,Base3): <statement>  depth-first, left-to-right  problem: class derived from two classes with a common base class Nov 6, 2014 Advanced Programming
  • 63. Private variables  No real support, but textual replacement (name mangling)  __var is replaced by _classname_var  prevents only accidental modification, not true protection Advanced Programming
  • 64. ~ C structs  Empty class definition: class Employee: pass john = Employee() john.name = 'John Doe' john.dept = 'CS' john.salary = 1000 Advanced Programming
  • 65. Exceptions  syntax (parsing) errors while 1 print 'Hello World' File "<stdin>", line 1 while 1 print 'Hello World' ^ SyntaxError: invalid syntax  exceptions  run-time errors  e.g., ZeroDivisionError, NameError, TypeError Nov 6, 2014 Advanced Programming
  • 66. Handling exceptions Nov 6, 2014 Advanced Programming while 1: try: x = int(raw_input("Please enter a number: ")) break except ValueError: print "Not a valid number"  First, execute try clause  if no exception, skip except clause  if exception, skip rest of try clause and use except clause  if no matching exception, attempt outer try statement
  • 67. Handling exceptions  try.py import sys for arg in sys.argv[1:]: try: f = open(arg, 'r') except IOError: print 'cannot open', arg else: print arg, 'lines:', len(f.readlines()) f.close  e.g., as python try.py *.py
  • 68. Language comparison Tcl Perl Python JavaScript Visual Basic Speed development      regexp    breadth extensible    embeddable   easy GUI   (Tk)  net/web      enterprise cross-platform     I18N     thread-safe    database access     