Last login: Thu Aug 26 09:10:25 on ttys001 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:Thu Aug 26:10:21:~> python Python 3.8.11 (default, Aug 6 2021, 08:56:27) [Clang 10.0.0 ] :: Anaconda, Inc. on darwin Type "help", "copyright", "credits" or "license" for more information. >>> x = [] >>> y = [] >>> x == y True >>> x is y False >>> id(x) 140504783066752 >>> id(y) 140504783240384 >>> x = "cows" >>> y = "cows" >>> x == y True >>> x is y True >>> x[0] = "C" Traceback (most recent call last): File "", line 1, in TypeError: 'str' object does not support item assignment >>> x = 5 >>> y = 5 >>> x == y True >>> x is y True >>> id(x) 4317584000 >>> hex(id(x)) '0x101591a80' >>> x not is y File "", line 1 x not is y ^ SyntaxError: invalid syntax >>> x is not y False >>> x = [] >>> y = x >>> y.append(5) >>> y [5] >>> x [5] >>> x is y True >>> "aliasing" 'aliasing' >>> #Mutablity is convenient, and dangerous. >>> t = (1, 2, 3) >>> t (1, 2, 3) >>> t[0] 1 >>> t[0] = 5 Traceback (most recent call last): File "", line 1, in TypeError: 'tuple' object does not support item assignment >>> type(t) >>> x = [1,2,3] >>> t (1, 2, 3) >>> x [1, 2, 3] >>> id(x) 140504783066752 >>> x = x + [4,5,6] >>> id(x) 140504783305216 >>> x = [1,2,3] >>> id(x) 140504783066752 >>> x.append(4) >>> x [1, 2, 3, 4] >>> id(x) 140504783066752 >>> t.append(4) Traceback (most recent call last): File "", line 1, in AttributeError: 'tuple' object has no attribute 'append' >>> id(t) 140504782866048 >>> t = t + (4,5,6) >>> t (1, 2, 3, 4, 5, 6) >>> id(t) 140504782490496 >>> animal = File "", line 1 animal = ^ SyntaxError: invalid syntax >>> animal = "cow" >>> id(animal) 140504783306672 >>> animal += "pie" >>> animal 'cowpie' >>> id(animal) 140504783314992 >>> len(animal) 6 >>> t (1, 2, 3, 4, 5, 6) >>> len(t) 6 >>> 7 in t False >>> x [1, 2, 3, 4] >>> 4 in x True >>> "cow" in "cowpie" True >>> z Traceback (most recent call last): File "", line 1, in NameError: name 'z' is not defined >>> "ce" in "cowpie" False >>> x [1, 2, 3, 4] >>> x[1:] [2, 3, 4] >>> x[1:4] [2, 3, 4] >>> x[4] Traceback (most recent call last): File "", line 1, in IndexError: list index out of range >>> x[-1] 4 >>> x[-2] 3 >>> t (1, 2, 3, 4, 5, 6) >>> t[1:] (2, 3, 4, 5, 6) >>> t[1:4] (2, 3, 4) >>> t[6] Traceback (most recent call last): File "", line 1, in IndexError: tuple index out of range >>> s = "abcdefg" >>> s[1:] 'bcdefg' >>> s[1:4] 'bcd' >>> #### Lists are diffeent >>> ## Who is Rosemary Woods? >>> foo = ["I", "am", "not", "a", "crook"] >>> foo[1,3] Traceback (most recent call last): File "", line 1, in TypeError: list indices must be integers or slices, not tuple >>> foo[1:3] ['am', 'not'] >>> foo[1:3] = [] >>> foo ['I', 'a', 'crook'] >>> foo ['I', 'a', 'crook'] >>> foo[1:1] [] >>> foo[1:1] = "cookiewoofage" >>> foo ['I', 'c', 'o', 'o', 'k', 'i', 'e', 'w', 'o', 'o', 'f', 'a', 'g', 'e', 'a', 'crook'] >>> foo[:15] = [] >>> foo ['crook'] >>> #NC-17 sequences have iterators inside of them >>> #Iterators determine how a sequence is walked through. >>> list(t) [1, 2, 3, 4, 5, 6] >>> list("Iowa sow") ['I', 'o', 'w', 'a', ' ', 's', 'o', 'w'] >>> "* File "", line 1 "* ^ SyntaxError: EOL while scanning string literal >>> "* File "", line 1 "* ^ SyntaxError: EOL while scanning string literal >>> "*"*50 '**************************************************' >>> "*"*1.5 Traceback (most recent call last): File "", line 1, in TypeError: can't multiply sequence by non-int of type 'float' >>> "*"*(-2) '' >>> x = ["hello", 42] >>> max(x) Traceback (most recent call last): File "", line 1, in TypeError: '>' not supported between instances of 'int' and 'str' >>> x = [4,2,8,5,3] >>> max(x) 8 >>> min(x) 2 >>> ##homogeneious sequence of orderable items. >>> >>> x = [complex(0,0), complex(1,1)] >>> x [0j, (1+1j)] >>> max(x) Traceback (most recent call last): File "", line 1, in TypeError: '>' not supported between instances of 'complex' and 'complex' >>> 'mississippi'.count("i") 4 >>> x = [1,2,3,4,5]