Monday, November 30, 2009

byte of python 2

Continue learning Python after thanksgiving breaks.

Some notes about flow control:
* It's very interesting to see that python has an if-elif-else statement. A colon has to be placed after each statement (if, elif, else) to indicate the beginning of the block.
* An optional else statement can be created after a for or while loop.
* range(1,5,2) means [1,3] (start from 1, step 2, up to 5)
* use break or continue statements for more control.

Some notes about function:
* "def foo(a,b=4):" defines a function named foo with inputs a and optional input b equals to 4.
* inside functions, use global var to make var global so that one can change the value of var inside function.
* Docstrings are cool. The author suggested using it this way - "The convention followed for a docstring is a multi-line string where the first line starts with a capital letter and ends with a dot. Then the second line is blank followed by any detailed explanation starting from the third line."

Some notes about Python data structure:
* So far, I have felt that Python is a very flexible language. Its data structures(list, tuple, dictionary, set) are very interesting. Slicing each structure is also fun.
* One thing I want to mention is that Python binds name to an object. The name only refers to the object but not represent the object itself. So "if you want to make a copy of a list or such kinds of sequences or complex objects (not simple objects such as integers), then you have to use the slicing operation to make a copy."
shoplist = ['apple', 'mango']
mylist = shoplist[:]

Wednesday, November 25, 2009

byte of python

After searching for a good tutorial for python beginners, I found this one here. In that 118 pages pdf file, I went through the first 20 very quickly and then finally begin to learn some python. So here is some of my class notes. I have a google notebook, but not quite like it though.

* ctrl-d or ctrl-z to quit Python (I really wish I knew this one before.)
* comment symbol is #
* ' and '' are interchangeable, escape sequences for them is \ and \\
* \n new line, \t tab
* add "r" before expression to indicate raw string
* implicit line join using \
* Python is a very flexible language, 'a'+'b' gives 'ab' (first time I see something like this)
* Boolean NOT, AND, OR are not, and, or (different with R)

Grand-opening day!

I have been thinking about opening a blog of my own for a long time. Before this one, I have been the "chief editor" of my 2 year old boy for, hmm, 2 years! It's time to start my own business.