06 2020 档案

摘要:举例说明: # 引入copy模块 import copy lst1 = [1, 2, 3, ["a", "b"]] # 赋值操作 lst2 = lst1 # 切片操作,会产生新的列表-浅拷贝 lst3 = lst1[:] lst4 = lst1.copy() lst5 = copy.deepcopy 阅读全文
posted @ 2020-06-28 15:56 奔奔-武 阅读(198) 评论(0) 推荐(0)
摘要:字符串方法的操作:capitalize、upper、lower、swapcase、title、center、expandtabs、replace等 # TODO:字符串是不可变对象, 所以任何操作对原字符串不会有任何影响 str = "python⽜BA" # 首字母大写 res = str.cap 阅读全文
posted @ 2020-06-11 13:21 奔奔-武 阅读(167) 评论(0) 推荐(0)
摘要:字符串切割函数split,以及需要留意的深坑! # 字符串切割 str = "我的昵称是奔奔,我的年龄是18,我的爱好是python" res = str.split(",") print(res) # 指定切割次数 res = str.split(",", 1) print(res) # TODO 阅读全文
posted @ 2020-06-11 11:39 奔奔-武 阅读(2165) 评论(0) 推荐(0)
摘要:int类型转换为bool类型时,0为False,非0为True str类型转换为bool类型时,空字符串和None为False,不空为True 以下为代码示例: 1 # int转换为bool 2 # 0是False 3 print(bool(0)) 4 # 非0是True 5 print(bool( 阅读全文
posted @ 2020-06-10 11:36 奔奔-武 阅读(14197) 评论(0) 推荐(0)