- 论坛徽章:
- 0
|
回复 #2 zhenglxd 的帖子
技术论坛请不要用类似这些用语,以避免引起其他人的反感
问题一:
》python 属于动态类型语言,任意一个变量只有在用到的时候才知道他的类型,变量不需要声明(其实为变量的引用)
例:
- >>> def prt(s):
- ... print s
- ...
- >>> prt('abcdef')
- abcdef
- >>> prt(12345)
- 12345
- >>> prt([1, 2, 3])
- [1, 2, 3]
- >>> prt((1, 2, 3))
- (1, 2, 3)
- >>> prt({1:'a', 2:'b'})
- {1: 'a', 2: 'b'}
- >>>
复制代码
本例中,prt 函数的参数,可以为任意类型
问题二:
》
python HOWTO 中说:
sub(replacement, string, [count=0])
replacement can also be a function, which gives you even more control.
If replacement is a function,
the function is called for every non-overlapping occurrence of pattern.
On each call,
the function is passed a MatchObject argument for the match and can use this information
to compute the desired replacement string and return it.
[ 本帖最后由 izhier 于 2009-3-3 14:11 编辑 ] |
|