Presentation is loading. Please wait.

Presentation is loading. Please wait.

Python : highlights Based on T. K. Prasad’s slides.

Similar presentations


Presentation on theme: "Python : highlights Based on T. K. Prasad’s slides."— Presentation transcript:

1 Python : highlights Based on T. K. Prasad’s slides

2 Versatile Improved Scripting : Replaced Bash Jython Snippets – Succinct code for JVM target: Replaced Java Short Programs

3 Striking Features Indentation based block structure promotes succinctness and improves readability Lack of separate variable/field declaration – Pros: Concise Code (with suitably chosen names) – Cons: Lack of redundancy for static checking Powerful and convenient string handling Useful collections – Lists, Dictionaries (maps), Tuples, Arrays, etc – Uniformity and Convenience: strings vs lists Numbers : int, long, float, complex

4 (cont’d) Dynamic typing – Pros: Supports heterogeneous data structures akin to Scheme – Cons: Certain type errors cannot be detected – Duck Typing is a style of dynamic typing in which an object's current set of methods and properties determines the valid semantics, rather than its inheritance from a particular class or implementation of a specific interface.dynamic typingmethods Duck typing is aided by habitually not testing for the type of arguments in method and function bodies, relying on documentation, clear code, and testing to ensure correct use.

5 (cont’d) Multiparadigm Programming Language – Functional Style Views computation as a sequence of transformation – Imperative Style Views computation as a “large” sequence of “small” changes to the memory – Object-Oriented Style Views computation as interactions between a collection of computing agents (client-server paradigm)

6 List comprehension Imperative style for item in list: if conditional: expression Functional newlist =[expression for item in list if conditional]

7 List comprehension Imperative style y = [1, 2, 3] S=[] for v in y: s.append(v+1) Functional style – list comprehension y = [1,2,3] s = [ v+1 for v in y]

8 List comprehension import sys lines=[] for line in sys.stdin: if filter (line): # some function to determine the interesting lines lines.append(line) List comprehension: lines = [ line for line in sys.stdin if filter(line)]


Download ppt "Python : highlights Based on T. K. Prasad’s slides."

Similar presentations


Ads by Google