1. Eclipse多行注释 ctrl+/
2. Tuple, string and number is immutable, while list is mutable.
>>> t = 12345, 54321, 'hello!'
>>> t[0] = 88888
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
The keys in dictionary can NOT contain any mutable objects.
3. distutils.text_file.TextFile.readlines(): Read and return the list of all logical lines remaining in the current file. This updates the current line number to the last line of the file.
4. enumerate(iterable, start=0)
>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
>>> list(enumerate(seasons))
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
>>> list(enumerate(seasons, start=1))
[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
5. while加else的意思是只有在while正常结束循环的时候才执行else的语句,如果用非自然中断循环,比如用break跳出,则不执行。如果不加else,while循环不管怎么样结束,后边的语句都执行。(http://zhidao.baidu.com/question/468857592.html)
6. arithmetic:
>>> 5//3
1
>>> 5/3
1.66666666666666667
>>> divmod(5,3)
(1,2)
>>> num=5
>>> num +=1
>>> num
6
7. If you intend to define a function without any body inside, you can just use the built-in word pass.
8. A generator function is a function that returns iterator objects.
9. The difference between yield and return is the former picks up where it was left last time when it call the function again while the later always runs at the beginning of the function.
10. dict.get()key[, default])
Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to None, so that this method never raises a KeyError. (python.org)
11. Generator Objects are used to be iterators. And __iter__(self) makes an object iterable object.
12. Getting rid of the default new line in print function is achieved by adding end='' in the arguement list.
13. if __name__ == "__main__": main()
14. Users of the package can import individual modules from the package. This loads the submodule sound.effects.echo. It must be referenced with its full name.for example:
>>>import sound.effects.echo
>>>sound.effects.echo.echofilter(input, output, delay=0.7, atten=4)
15. An alternative way of importing the submodule is like following. This also loads the submodule echo, and makes it available without its package prefix, so it can be used as follows:
>>>from sound.effects import echo
>>>echo.echofilter(input, output, delay=0.7, atten=4)