Sunday, January 8, 2012

Start on Python

It's being quite a while since my last blog and I would like to have something really new to start the new year, Python.

Recently I started teaching my son Python. I don't know Python before. So I have to learn it while teaching him. I intended to learn Python for quite some time, but time has always been my biggest enemy, together with my memory: it's getting worse every year. If I learn something and don't use it immediately, then it's quite possible after 3 months, I'm new to it again. So I start blogging it, trying to make my memory last longer.

Python is an elegant language, it's very expressive and has very brief syntax - though this can be a double side sword - to a experienced programmer with long time Java/C#/C++/C experience, it takes some time to be used to it.

Some points about Python I'd like to note down:

  1. Python started at 1989, and first public appeared at 1991
  2. CPython is the C implemented version of Python, then standard Python
  3. Python generally has 2 kinds of primary types: numbers and strings, though array/list and hashtable/dictionary is first class member of the language.
  4. Python use space indention to indicate sub-scope. The indent does not have to be unified within program, but must be the same for the same scope
  5. like most script languages, variables do not need to be pre-claimed before being used
  6. Python can be compiled into byte codes, like Java class files, with extension .pyo or .pyc
  7. using '''/""", you can have multiple line strings
  8. raw string starts with a 'r': r"c:\a\path\file"
  9. unicode string starts with a 'u': u"this is unicode"
  10. raw_input() will return anything you input as a string, while input() will try to evaluate your input as Python code! For example:
    >>> a = 3
    >>> b = input()
    a+11
    >>> b
    14
  11. Python as +=, -=, *=, /=, similar to other languages, but no i++, ++i, i-- or --i. But ++i or --i won't give you any syntax error, since the +/- are treated two time sign prefix!

No comments:

Post a Comment