Some tips to use python
(1) While using interactive model in command line, you can use "_" instead of copying the number calculated in the last command line.
(2) exchange the values in a and b, simply type: b,a = a,b
(3) String formation
str.format = format(...)
"{0} {1} {2}".format(1, 2, 3)
"{a} {b} {c}".format(a=1, b=2, c=3)
"%" is not recommend
(4) Useful operators: lambda, filter, reduce, map
f = lambda x, y : x + y
r = map(func, seq)
result = filter(lambda x: x % 2, fib)
reduce(lambda x,y: x+y, [47,11,42,13])
(5) Learn to use Decorator.
@decorator
def function(a, b):
return(a)
(6) get the path of ***
the path of a module : os.path.realpath(module.__file__)
the path of the current script : os.path.realpath(__file__)
(7) exec、 eval、 execfile and compile (a link)
exec 'print "Hello World"'
(6) get the path of ***
the path of a module : os.path.realpath(module.__file__)
the path of the current script : os.path.realpath(__file__)
(7) exec、 eval、 execfile and compile (a link)
exec 'print "Hello World"'
To be continue
没有评论:
发表评论