嵌套列表
使用嵌套列表即在列表里创建其它列表,例如:
>>>a = ['a', 'b', 'c']>>> n = [1, 2, 3]>>> x = [a, n]>>> x[['a', 'b', 'c'], [1, 2, 3]]>>> x[0]['a', 'b', 'c']>>> x[0][1]'b'
列表比较
列表比较需要引入 operator 模块的 eq 方法(详见:Python operator 模块):
实例
# 导入 operator 模块
importoperator
a =[1,2]
b =[2,3]
c =[2,3]
print("operator.eq(a,b): ",operator.eq(a,b))
print("operator.eq(c,b): ",operator.eq(c,b))
以上代码输出结果为:
operator.eq(a,b): False
operator.eq(c,b): True