摘要: 构造一个空Counter import collections c = collections.Counter() c.update('abcdaab') print(c) # Counter({'a':3,'b':2, 'c':1,'d':1}) c.update({'a':1,'d':5}) p 阅读全文
posted @ 2022-03-08 14:08 我在路上回头看 阅读(411) 评论(0) 推荐(0)
摘要: # 作用 都是格式化原形输出,!r用于format格式化,%r用于%格式化 # 示例 a = '123' b = 'hello, {!r}'.format(a) b = 'hello, %r' % (a) print(b) # hello, '123' 阅读全文
posted @ 2022-03-08 11:29 我在路上回头看 阅读(2176) 评论(0) 推荐(0)
摘要: # rpartition 从目标字符串的末尾也就是右边开始搜索分割符,如果字符串包含指定的分割符 则返回一个3元的元组,第一个为分割符左边的子串,第二个为分割符本身, 第三个为分割符右边的字串。 str = "www.baidu.com" print(str.rpartition(".")) # ( 阅读全文
posted @ 2022-03-08 10:56 我在路上回头看 阅读(58) 评论(0) 推荐(0)
摘要: 如果在模块中写上__all__=["test","class","XXX"],在其他人想要导入该模块时, 就只会导入在__all__列表中标明的方法、类或者是全局变量, 这些方法、类和全局变量以字符串的形式写入。这样可以防止别人在导入该模块时导入其不需要的东西 阅读全文
posted @ 2022-03-08 10:36 我在路上回头看 阅读(48) 评论(0) 推荐(0)