print """ ———————————————————————————————————————#4_08_callable 函数—————————————————————————————————————————————— """ # callable接收任何对象最为参数,如果参数对象是可调用的则返回True,否则返回False # 可调用的对象包括:函数、类方法,甚至是类本身 print string.punctuation print string.join print callable(string.punctuation) print callable(string.join) print string.join.__doc__ """ |string 模块中的函数现在已经不赞成使用了(尽管很多人现在仍然还在使用join函数) -|这个模块中包含许多有用的变量,如:punctuation,这个字符串包含了所有标准的标点符号字符。 |任何可调用的对象都可能会含有一个doc srting -|通过将callable函数作用于一个对象的每个属性,可以确定哪些属性(方法、函数、类)是你要关注的 -|哪些是你可以忽略的(例如常量等等) """ #—————————————————————————————————————————————————— print """ ———————————————————————————————————————#4_09_内置函数 built in函数—————————————————————————————————————————————— """ # bulit-in functions 内置函数 """ type、str、dir等其它Python内置函数都归组到__builtin__这个特殊的模块中""" print info(__builtin__)
# -*- coding: utf-8 -*- import odbchelper from example4_1_introspection import info li=[] print info(li) print """ ———————————————————————————————————————#4_02_可选参数和命名参数 optional and named arguments—————————————————————————————————————————————— """ """ spacing和collapse就是可选参数,定义了缺省值 object是必备参数,没有指定缺省值 通过使用named arguments(命名参数),参数在写入的顺序就可以自由指定了 """ print info(odbchelper) print info(odbchelper,12) print info(odbchelper,collapse=0) print info(spacing=15,object=odbchelper)