1.func可以引入任意多的整型参数,结果返回其中最大与最小的值
def max_min(*num):
for i in num:
if not isinstance(i,int):
return '参数不正确'
else:
return max(num),min(num)
2.定义一个方法func,该func可以引入任意多的字符串参数,结果返回(长度)最长的字符串。
def max_len(*str1):
longest = len(str1[0])
for i in str1[1:len(str1)]:
if len(i)>=longest:
longest = len(i)
return longest,i
3.定义一个方法get_doc(module),module参数为该脚本中导入或定义的模块对象,该函数返回module的帮助文档。
def get_doc(module):
return module.__doc__
import time
def get_doc(module):
return module.__doc__
import time
例 print get_doc(urllib),则会输出urllib这个模块的帮助文档。
4.定义一个方法get_text(f),f参数为任意一个文件的磁盘路径,该函数返回f文件的内容。
import linecache
def get_text(path):
fine = linecache.getlines(path)
return fine
def get_text(path):
fine = linecache.getlines(path)
return fine