Day 2 基础
数据类型
- 整型
- 浮点型
- 字符串
- 布尔型
- 列表
list = ['Google', 'Runoob', 1997, 2000]; #使用 print("list1[0]: ", list[0]) # 列表元素个数 len(list) # 列表元素最大值,最小值 max(list) min(list) #将元组转换为列表 list((a,b,c,d)) # 在列表末尾添加新的对象 list.append(2019) # 统计某个元素在列表中出现的次数 list.count(2019) # 在列表末尾一次性追加另一个序列中的多个值 list.extend((1,2,3)) # 从列表中找出某个值第一个匹配项的索引位置 list.index(2019) # 在指定位置插入新元素 list.insert(1,'new') # 移除列表中指定位置元素(默认最后一个元素),并且返回该元素的值 list.pop(1) # 移除列表中某个值的第一个匹配项 list.remove('new') # 反向列表中元素 list.reverse() # 对原列表进行排序 list.sort() # 清空列表 list.clear() # 复制列表 list.copy() # 更新 list[2] = 2001 #删除 del list[2]
- 元组, 和列表类似,但不可修改
tup = ('Google', 'Runoob', 1997, 2000); # 计算元素个数 len(tup) # 元素是否存在 print(2000 in tup)
- 字典 Set
thisset = set(("Google", "Runoob", "Taobao")) thisset.add("Facebook") # 添加 新元素位置随机 print(thisset) thisset.update({1,2}) print(thisset) thisset.update([3,4],[5,7]) # 修改 print(thisset) thisset.remove(3) # 移除元素,如果元素不存在会发生异常 thisset.discard(3) # 移除元素,如果元素不存在不会发生异常