随笔分类 -  Python基础

摘要:注:dic表示定义的一个字典变量,如:dic = {'name': 'shawn', 'age': 18} 增: 1. dic['love'] = 'girl' 直接通过新的键值对进行添加 dic = {'name': 'shawn', 'age': 18} dic['love'] = 'girl' 阅读全文
posted @ 2019-12-25 18:29 Shawn-Hu 阅读(599) 评论(0) 推荐(0)
摘要:注:lst为定义的列表变量,如:lst = [1, 2, 3, 4, 5] 增: 1. lst.append() 末尾追加 lst = [1, 2, 3, 4, 5, 6] lst.append(7) print(lst) 打印结果: [1, 2, 3, 4, 5, 6, 7] View Code 阅读全文
posted @ 2019-12-25 11:18 Shawn-Hu 阅读(198) 评论(0) 推荐(0)
摘要:注:s表示定义的一个字符串变量,如:s = 'hello string' 1. s.index() 查找元素,若查到则返回该元素索引,含多个该元素则返回第一个,查不到则报错 s = 'hello string' # 有且唯一的情况 res = s.index('e') print(res) 打印结果 阅读全文
posted @ 2019-12-24 20:02 Shawn-Hu 阅读(424) 评论(0) 推荐(0)