Last login: Fri Sep 4 10:15:18 on ttys006 The default interactive shell is now zsh. To update your account to use zsh, please run `chsh -s /bin/zsh`. For more details, please visit https://support.apple.com/kb/HT208050. (base) MAC:Fri Sep 04:14:11:~> x = [] -bash: x: command not found (base) MAC:Fri Sep 04:14:20:~> python Python 3.7.4 (default, Aug 13 2019, 15:17:50) [Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin Type "help", "copyright", "credits" or "license" for more information. >>> x = [] >>> type(x) >>> x.append("pigs") >>> x.append("horses") >>> x.append("cows") >>> x ['pigs', 'horses', 'cows'] >>> x.append(5) >>> x ['pigs', 'horses', 'cows', 5] >>> #lists are heterogeneous ... >>> x.append([1,2,3,"buffalo"]) >>> x ['pigs', 'horses', 'cows', 5, [1, 2, 3, 'buffalo']] >>> len(x) 5 >>> x[0] 'pigs' >>> x[0][0] 'p' >>> x[4][3] 'buffalo' >>> x[4][3][1:] 'uffalo' >>> s Traceback (most recent call last): File "", line 1, in NameError: name 's' is not defined >>> s = "abcdef" >>> list(s) ['a', 'b', 'c', 'd', 'e', 'f'] >>> "ab" in "baobab" True >>> x ['pigs', 'horses', 'cows', 5, [1, 2, 3, 'buffalo']] >>> "horses" in x True >>> "zebra" in x False >>> [1,2,3] + [4,5,6] [1, 2, 3, 4, 5, 6] >>> a = [1,2,3,4] >>> a[1:] [2, 3, 4] >>> a[:1] [1] >>> a[1:3] [2, 3] >>> a[1:3] = [] >>> a [1, 4] >>> a[1] = -7 >>> a [1, -7] >>> >>> original = [] >>> copy = original >>> original.append("foo") >>> original ['foo'] >>> copy ['foo'] >>> original is copy True >>> a = [1,2,3] >>> b = a[:] >>> a is b False >>> b [1, 2, 3] >>> b.append(4) >>> a [1, 2, 3] >>> b [1, 2, 3, 4] >>> s = "insane" >>> t = "insane" >>> s == t True >>> s is t True >>> x = 5 >>> y = 6 >>> x is y False >>> ##relational operators ... >>> # < > <= >= == != is ... >>> "5" == 5 False >>> 5**2==25 True >>> 5 < 6 True >>> 5 > 6 False >>> 5 <=6 True >>> 5 >= 6 False >>> 5 == 6 False >>> 5 != 6 True >>> x = ["cow", "pig", "horse", "goat", "chicken", "goose"] >>> x.sort() >>> x ['chicken', 'cow', 'goat', 'goose', 'horse', 'pig'] >>> x = ["pollard", "Warner", "monson", "Vaduri", "Fawcett"] >>> x ['pollard', 'Warner', 'monson', 'Vaduri', 'Fawcett'] >>> x.sort() >>> x ['Fawcett', 'Vaduri', 'Warner', 'monson', 'pollard'] >>> ## lex means word ... ## lexicon is a dictionary ... ## lexicographical ordering ... >>> ## asciicographical lexicographical, order based on byte value ... >>> ord("a") 97 >>> ord("A") 65 >>> ord(120) Traceback (most recent call last): File "", line 1, in TypeError: ord() expected string of length 1, but int found >>> chr(120) 'x' >>> chr(945) 'α' >>> chr(948) 'δ' >>> chr(946) 'β' >>> chr(947) 'γ' >>> foolish = [True, 5, "caterwaul", 5.6] >>> foolish.sort() Traceback (most recent call last): File "", line 1, in TypeError: '<' not supported between instances of 'str' and 'int' >>> "cow" 56 File "", line 1 "cow" 56 ^ SyntaxError: invalid syntax >>> "cow" < 56 Traceback (most recent call last): File "", line 1, in TypeError: '<' not supported between instances of 'str' and 'int' >>> "cow" == 56 False >>> x = [[2,3,4], [-3,1, 5], [5], [12, 5 -6], [2,3,5]] >>> x = [[2,3,4], [-3,1, 5], [5], [12, 5, -6], [2,3,5]] >>> x.sort() >>> x [[-3, 1, 5], [2, 3, 4], [2, 3, 5], [5], [12, 5, -6]] >>> min(x) [-3, 1, 5] >>> max(x) [12, 5, -6] >>> y = [2,4,2,5,6,8,9,1,3,0] >>> y.count(2) 2 >>> y.index(2) 0 >>> y.index(57) Traceback (most recent call last): File "", line 1, in ValueError: 57 is not in list >>> 57 in y False >>>