以下を参照。
変更可能なシーケンス (list 型) の演算
>>> s = ['a'] >>> s ['a'] >>> s[0] = 1 >>> s [1] >>> s = [0,1,2,3,4,5] >>> s[0] = 100 >>> s [100, 1, 2, 3, 4, 5] >>> s[2:4] = 'a' >>> s [100, 1, 'a', 4, 5] >>> del s[1:4] >>> s [100, 5] >>> s.append('python') >>> s [100, 5, 'python'] >>> s.extend('jython') >>> s [100, 5, 'python', 'j', 'y', 't', 'h', 'o', 'n'] >>> s.extend(100) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'int' object is not iterable >>> s.extend([100]) >>> s [100, 5, 'python', 'j', 'y', 't', 'h', 'o', 'n', 100] >>> s.count(100) 2 >>> s.count('python') 1 >>> s.index(100) 0 >>> s.index(100, 5) 9 >>> s.index('n') 8 >>> s.index('n', 0, 3) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: list.index(x): x not in list >>> s.index('n', 0, 10) 8 >>> s [100, 5, 'python', 'j', 'y', 't', 'h', 'o', 'n', 100] >>> s.insert(2, 3000) >>> s [100, 5, 3000, 'python', 'j', 'y', 't', 'h', 'o', 'n', 100] >>> s.remove(5) >>> s [100, 3000, 'python', 'j', 'y', 't', 'h', 'o', 'n', 100] >>> s.pop() 100 >>> s [100, 3000, 'python', 'j', 'y', 't', 'h', 'o', 'n'] >>> s.pop(0) 100 >>> s [3000, 'python', 'j', 'y', 't', 'h', 'o', 'n'] >>> s.reverse() >>> s ['n', 'o', 'h', 't', 'y', 'j', 'python', 3000] >>> s.sort() >>> s [3000, 'h', 'j', 'n', 'o', 'python', 't', 'y']