Python 2.7.4 (default, Sep 26 2013, 03:20:26) [GCC 4.7.3] on linux2 Type "copyright", "credits" or "license()" for more information. >>> seq = [0, "hello", 4.59, 'c'] >>> seq [0, 'hello', 4.59, 'c'] >>> seq[1] 'hello' >>> seq[-1] 'c' >>> seq[3] 'c' >>> len(seq) 4 >>> seq[2] 4.59 >>> seq[2]*2 9.18 >>> seq [0, 'hello', 4.59, 'c'] >>> seq[2] = seq[2]*2 >>> seq [0, 'hello', 9.18, 'c'] >>> seq[2] *= 2 >>> seq [0, 'hello', 18.36, 'c'] >>> seq * 2 [0, 'hello', 18.36, 'c', 0, 'hello', 18.36, 'c'] >>> seq [0, 'hello', 18.36, 'c'] >>> >>> >>> seq *= 2 >>> seq [0, 'hello', 18.36, 'c', 0, 'hello', 18.36, 'c'] >>> seq[2] = 13.2435 >>> seq [0, 'hello', 13.2435, 'c', 0, 'hello', 18.36, 'c'] >>> seq / 2 Traceback (most recent call last): File "", line 1, in seq / 2 TypeError: unsupported operand type(s) for /: 'list' and 'int' >>> seq[0:3] [0, 'hello', 13.2435] >>> seq[0:4] [0, 'hello', 13.2435, 'c'] >>> seq[:len/2] Traceback (most recent call last): File "", line 1, in seq[:len/2] TypeError: unsupported operand type(s) for /: 'builtin_function_or_method' and 'int' >>> seq[:len(seq)/2] [0, 'hello', 13.2435, 'c'] >>> seq[10] Traceback (most recent call last): File "", line 1, in seq[10] IndexError: list index out of range >>> seq[5:8] ['hello', 18.36, 'c'] >>> seq[5:10] ['hello', 18.36, 'c'] >>> seq[2:-2] [13.2435, 'c', 0, 'hello'] >>> seq [0, 'hello', 13.2435, 'c', 0, 'hello', 18.36, 'c'] >>> seq[2:0] [] >>> mylist = [] >>> mylist [] >>> mylist += [23, 45] >>> mylist [23, 45] >>> mylist += 51 Traceback (most recent call last): File "", line 1, in mylist += 51 TypeError: 'int' object is not iterable >>> mylist += [51] >>> mylist [23, 45, 51] >>> val = 100 >>> mylist += [val] >>> mylist [23, 45, 51, 100] >>> 'c' in seq True >>> seq.find('c') Traceback (most recent call last): File "", line 1, in seq.find('c') AttributeError: 'list' object has no attribute 'find' >>> seq.index('c') 3 >>> seq.index('c',4,8) 7 >>> 100 in seq False >>> 100 in mylist True >>> mylist += 51 Traceback (most recent call last): File "", line 1, in mylist += 51 TypeError: 'int' object is not iterable >>> for val in seq: print val 0 hello 13.2435 c 0 hello 18.36 c >>> str(seq) "[0, 'hello', 13.2435, 'c', 0, 'hello', 18.36, 'c']" >>> print str(seq) [0, 'hello', 13.2435, 'c', 0, 'hello', 18.36, 'c'] >>> seq [0, 'hello', 13.2435, 'c', 0, 'hello', 18.36, 'c'] >>> print seq [0, 'hello', 13.2435, 'c', 0, 'hello', 18.36, 'c'] >>> for val in seq: print val, 0 hello 13.2435 c 0 hello 18.36 c >>> >>> seq.count('c') 2 >>> seq.count(c) Traceback (most recent call last): File "", line 1, in seq.count(c) NameError: name 'c' is not defined >>> seq.count(100) 0 >>> seq.index(100) Traceback (most recent call last): File "", line 1, in seq.index(100) ValueError: 100 is not in list >>> seq [0, 'hello', 13.2435, 'c', 0, 'hello', 18.36, 'c'] >>> seq.insert(4, "py") >>> seq [0, 'hello', 13.2435, 'c', 'py', 0, 'hello', 18.36, 'c'] >>> seq.remove('hello') >>> seq [0, 13.2435, 'c', 'py', 0, 'hello', 18.36, 'c'] >>> seq.remove(100) Traceback (most recent call last): File "", line 1, in seq.remove(100) ValueError: list.remove(x): x not in list >>> if 100 in seq: seq.remove(100) >>> seq [0, 13.2435, 'c', 'py', 0, 'hello', 18.36, 'c'] >>> s = "hello" >>> line = "how are 10 you?" >>> s 'hello' >>> s[0] 'h' >>> seq[0] = 10 >>> seq [10, 13.2435, 'c', 'py', 0, 'hello', 18.36, 'c'] >>> s[0] = 'H' Traceback (most recent call last): File "", line 1, in s[0] = 'H' TypeError: 'str' object does not support item assignment >>> s.capitalize() 'Hello' >>> s 'hello' >>> s = s.capitalize() >>> s = 'hello SyntaxError: EOL while scanning string literal >>> s = 'hello' >>> s 'hello' >>> w = "what's up?" >>> w "what's up?" >>> s 'hello' >>> w "what's up?" >>> line 'how are 10 you?' >>> s + w "hellowhat's up?" >>> phrase = s + ' ' + w >>> phrase "hello what's up?" >>> s + '\n' + w "hello\nwhat's up?" >>> phrase = s + '\n' + w >>> print phrase hello what's up? >>> phrase "hello\nwhat's up?" >>> s[-1] 'o' >>> s 'hello' >>> phrase[-3] 'u' >>> phrase[3,8] Traceback (most recent call last): File "", line 1, in phrase[3,8] TypeError: string indices must be integers, not tuple >>> phrase[3:8] 'lo\nwh' >>> phrase[3] 'l' >>> phrase[3] = 'J SyntaxError: EOL while scanning string literal >>> >>> phrase[3] = 'J' Traceback (most recent call last): File "", line 1, in phrase[3] = 'J' TypeError: 'str' object does not support item assignment >>> phrase.count('o') 1 >>> phrase "hello\nwhat's up?" >>> s 'hello' >>> phrase.count('l') 2 >>> phrase.find('l') 2 >>> phrase.find('o') 4 >>> w.rjust(15) " what's up?" >>> w.split() ["what's", 'up?'] >>> phrase.split() ['hello', "what's", 'up?'] >>> wseq = phrase.split() >>> wseq ['hello', "what's", 'up?'] >>> line = "12,100,24,10" >>> line.split() ['12,100,24,10'] >>> line.split(,) SyntaxError: invalid syntax >>> line.split(',') ['12', '100', '24', '10'] >>> line += ',13-25-39482' >>> line '12,100,24,10,13-25-39482' >>> line.split(',-') ['12,100,24,10,13-25-39482'] >>>