1: raw_input() 2: '//' stands for floating divide,and should know the difference between '/' and '//' 3: '**' means power, for example 2**3 = 8; 2**1 = 2; 4: enumerate, for example for index, ch in enumerate(str): print index 5: In the operations of file, '+' = 'rw', and 'a' means that add something to the end of file. 6: class Test(object): class_variable = 'andy' pass The point is to understand how use 'class variable' 7: sys.platform, sys.version 8: functional helper method: range(start, end, step); type(obj) dir(obj) 9: understand how use '\' and ';' 10: comprehend the follow lines ls = os.linesep a = ['and', 'hell'] file.writelines(["%s%s" % (x, ls) for x in a]) 11: understand the means of a[::n] 12: try to find the same and difference among the follow lines (a) a = b = 2.0 (b) a = 2.0 ; b = a; (c) a = 2.0; b = 2.0; (d) a = 2.0; b = 1.8 + 0.2 id(a) == id(b) == a is b notes, int and string have another explains when I test, python can cache from -5 to 257, and it will change, please don't use this property 13: repr(s); return string if inistance (num, (int, long): print 'hellp' 14: max and reduce http://blog./2008/02/19/python-function-max-and-reduce/ sort(reverse=True) stands for descending order enumerate(a) generate [index, column] 15: How to use zip a = [1, 2]; b =['a', 'b'] zip(a,b); return [(1, 'a'), (2, 'b')] test = zip(a,b) c, d = zip(*test) http://apps.hi.baidu.com/share/detail/35028002 16: Generally speeking, in consideration of performance, we should not write repeated funtion call in the circle. For example: while i < len(my_string): print i we shoud do like follow: length = len(my_string) while i < lenght: pass In addition for substring in my_string[1:] if substring not in a + b pass 17 from string import Template s = Template("I'm ${name}") pritn s.substitute(name="andy")
|
|
来自: 非常尛貝 > 《python核心编程》