Saturday, 30 March 2013

First impression of Python

Born some two decades ago, Python has certainly accumulated enough interests to become one of the most popular programming languages used in the financial industry.

Designed to be a write-less-do-more language, Python has certain aspects that differ from Java:
  1. It is an interpreted language, which means no compilation is required. 
  2. It is not a strongly typed language
  3. Its statement grouping is done by indentation instead of open and close braces
  4. It does not require declaration of variable or argument
  5. It supports complex number, for example (using Python interactive interpreter)
  6. >>> 1j + 2J
    (-2+0j)
    >>> (1+2j) * complex(2,3)
    (-4+7j)
    
  7. Strings can be subscripted. For example, the first character of a string has index 0.
  8. >>> word="HelloWorld"
    >>> word[4]
    'o'
    >>> word[1:3]   # using the slice notation, returning characters from index 1 to 2
    'el'
    
  9. It supports multiple assignment, for example, 'a,b=b,a+b', where the expression on the right-hand side 'b,a+b' are evaluated first before any of the assignments take place
  10. Not surprisingly, it supports lamda forms
  11. >>> def incresedBy(n):
    ...     return lambda x: x + n
    ...
    >>> f = incresedBy(42)
    >>> f(1)
    43
    
  12. It supports map and reduce functions as part of its functional programming offerings
  13. It supports Tuples, which are immutable and usually contain an heterogeneous sequence of elements
  14. >>> t=123,321,'hello'
    >>> t
    (123, 321, 'hello')
    
  15. It allows multiple inheritance, for example
  16. class DerivedClassName(Base1, Base2, Base3):
        <statement-1>
        .
        .
        .
        <statement-N>
    

No comments:

Post a Comment