
Python
loneba
总结-学习-分享
展开
-
Python去除字符串空格
Microsoft Windows [版本 6.1.7601]版权所有 (c) 2009 Microsoft Corporation。保留所有权利。C:\Users\Administrator.ZHANGHAO-PC>pythonPython 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (...原创 2020-01-15 06:52:03 · 377 阅读 · 0 评论 -
python正则表达式flags参数使用
介绍re.I、re.DEBUG、re.S的使用,多个flags如何使用;正则表达式贪婪模式、非贪婪模式使用实例,re.search()正则表达式传变量。C:\Users\Administrator.ZHANGHAO-PC>pythonPython 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit ...原创 2020-01-14 07:18:17 · 2553 阅读 · 1 评论 -
Python Set intersection
Python Set intersection()转自:https://www.programiz.com/python-programming/methods/set/intersectionThe intersection() method returns a new set with elements that are common to all sets.The interse...转载 2018-11-10 08:12:56 · 736 阅读 · 0 评论 -
如何判断某些字符是否是字典的键值
字典的键值是列表>>> dict2={'host':'earth','port':80}>>> dict2.values()['earth', 80]>>> dict2.keys()['host', 'port']判断字典dict2是否存在键‘host’>>> 'host' in dict2True&g...原创 2018-11-10 08:36:29 · 9589 阅读 · 0 评论 -
Google Python入门题学习--list
写了3个函数,前2个函数基本与答案一致,只是多增加了些打印。第3个与答案差异较大,比我的答案简洁很多。主要是对sorted的用法不太熟悉,不知道key参数的含义。查了下资料。The value of the key parameter should be a function that takes a single argument and returns a key to use for s...原创 2018-11-19 07:45:23 · 404 阅读 · 0 评论 -
Python re.match()与re.search()的差异
re.match()只查找第1行是否匹配re.search()查找所有行是否匹配相同之处,匹配失败都返回空>>> name='zqg'>>>>>> reg=re.compile(r'I am %s' %name)>>> m=re.match(reg,'I am zqg')>>>原创 2018-11-23 07:13:21 · 885 阅读 · 0 评论 -
怎么把RF的Python自定义库函数的信息写入Report?
1、定义了如下Python库函数def print_name(name): if not name: raise AssertionError(u'name should not be empty') else: print name当执行失败时可以抛出异常,此例中使用AssertionError,若RF传入name为空,会把'name shou...原创 2018-11-27 07:46:56 · 332 阅读 · 0 评论 -
如何生成随机ipv4、ipv6地址和MAC地址
借助Python的fake库的internet包>>> from faker import Faker>>> from faker.providers import internet>>> fake=Faker()生成ipv4地址带掩码长度>>> fake.ipv4(network=True)'192.53...原创 2019-09-03 22:05:12 · 4652 阅读 · 0 评论 -
Python异常处理try except理解
第1段代码未使用try except,遇到异常退出,print('abc')未执行。执行结果如下def func1(a,b): return a/bif __name__=='__main__': func1(1,0) print('abc')D:\>python test_exception.pyTraceback (most recent ca...原创 2019-09-10 22:36:31 · 1506 阅读 · 2 评论