
正文
Python测验_函数 python测验1
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
python测试函数有哪些
测试函数是用于自动化测试Python测验_函数,使用python模块中Python测验_函数的unittest中Python测验_函数的工具来测试
附上书中摘抄来Python测验_函数的代码:
#coding=utf-8import unittestfrom name_function import get_formatted_nameclass NamesTestCase(unittest.TestCase): def test_first_last_name(self): formatted_name=get_formatted_name('janis','joplin') self.assertEqual(formatted_name,'Janis Joplin') def test_first_last_middle_name(self): formatted_name=get_formatted_name('wolfgang','mozart','amadeus') self.assertEqual(formatted_name,'Wolfgang Amadeus Mozart')#注意下面这行代码,不写会报错哦~~~书中没有这行if __name__=="__main__": unittest.main()
相关问答
Q1: Python 编写并测试函数change(str1),其功能是对参数str1进行大小写转换?
def change(str1):
new_str = str()
for i in range(len(str1)):
if(65 = ord(str1[i]) = 90):
a = str1[i].lower()
print(a,end='')
elif(97 = ord(str1[i]) = 122):
a = str1[i].upper()
print(a,end='')
else:
a = str1[i]
print(a,end='')
return new_str
str2 = str(input("要转换的字符串:"))
print(change(str2))
Q2: python中函数包括
1. print()函数:打印字符串
2. raw_input()函数:从用户键盘捕获字符
3. len()函数:计算字符长度
4. format(12.3654,'6.2f'/'0.3%')函数:实现格式化输出
5. type()函数:查询对象的类型
6. int()函数、float()函数、str()函数等:类型的转化函数
7. id()函数:获取对象的内存地址
8. help()函数:Python的帮助函数
9. s.islower()函数:判断字符小写
10. s.sppace()函数:判断是否为空格
11. str.replace()函数:替换字符
12. import()函数:引进库
13. math.sin()函数:sin()函数
14. math.pow()函数:计算次方函数
15. 3**4: 3的4次方
16. pow(3,4)函数:3的4次方
17. os.getcwd()函数:获取当前工作目录
18. listdir()函数:显示当前目录下的文件
19. socket.gethostbyname()函数:获得某主机的IP地址
20. urllib.urlopen(url).read():打开网络内容并存储
21. open().write()函数:写入文件
22. webbrowser.open_new_tab()函数:新建标签并使用浏览器打开指定的网页
23. def function_name(parameters):自定义函数
24. time.sleep()函数:停止一段时间
25. random.randint()函数:产生随机数
关于Python测验_函数和python测验1的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







