00-公共方法

来源:互联网 发布:js字符串变数组 编辑:程序博客网 时间:2024/06/06 16:35

公共方法

运算符

运算符 python表达式 结果 描述 支持的数据类型 + [1,2]+[3,4] [1,2,3,4] 合并 字符串、列表、元组 * ‘Hi’*4 [‘Hi’,’Hi’,’Hi’,’Hi’] 复制 字符串、列表、元组 in 3in(1,2,3) True 元素是否存在 字符串、列表、元组、字典 not in 4 not in(1,2,3) True 元素是否不存在 字符串、列表、元组、字典

python内置函数

序号 方法 描述 1 cmp(item1,item2) 比较两个值 2 len(item) 计算容器中元素个数 3 max(item) 返回元素中最大值 4 min(item) 返回元素中最小值 5 del(item) 删除元素变量

注意:
1. cmp 在比较字典数据时,先比键,在比较值
2. len 在操作字典数据时,返回的是键值对个数
3. del 两种用法
a. del 变量
b. del()

多维列表/元组访问的示例

   tuple = [(2,3),(4,5)]   tuple[0]# out (2,3)   tuple[0][0]# out 2   tuple[0][1]# out 3   touple2 = touple+[(3)]   touple2# out [(2,3),(4,5),3]   touple2[2]# out 3   touple2[2][0]# 错误 第三组没有第二个元素