Last login: Thu Feb 10 09:36:22 on ttys002 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. MAC:Thu Feb 10:10:21:~> python Python 3.10.0 (v3.10.0:b494f5935c, Oct 4 2021, 14:59:19) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> # < > <= >= != == relational operators >>> # is >>> # is checks for equality of identity >>> x = 5 >>> y = 5 >>> x == y True >>> x is y True >>> x = 5000 >>> y = 5000 >>> x == y True >>> x is y False >>> x = "cow" >>> y = "cow" >>> x == y True >>> x is y True >>> x = 3 >>> x += 5 >>> x *= 1 + 2 >>> x 24 >>> ## x op=y same as x = x op (y) >>> a = "abc" >>> id(a) 4312163376 >>> a += "def" >>> id(a) 4313114224 >>> count = 0 >>> count += 1 >>> count 1 >>> count += 1 >>> count 2 >>> count += 1 >>> count 3 >>> levels = [214.6, 214.7, 217.0, 218.5, 218.5, 218.4, 218.3, 218.1,# ... 217.9, 217.8, 217.5, 217.2, 217.2, 216.9, 216.8, 216.7, 216.7,# ... 216.9, 217.2, 217.3, 217.3, 217.1, 217.0, 216.7, 216.5, 216.3,# ... 216.2, 216.2, 216.3, 216.3, 216.3] >>> levels [214.6, 214.7, 217.0, 218.5, 218.5, 218.4, 218.3, 218.1, 217.9, 217.8, 217.5, 217.2, 217.2, 216.9, 216.8, 216.7, 216.7, 216.9, 217.2, 217.3, 217.3, 217.1, 217.0, 216.7, 216.5, 216.3, 216.2, 216.2, 216.3, 216.3, 216.3] >>> levels[0] 214.6 >>> levels[1] 214.7 >>> s = "abcdef" >>> s[0] 'a' >>> s[1] 'b' >>> len(s) 6 >>> len(levels) 31 >>> 214.6 in levels True >>> # in checks for membership of a object in a list using == >>> "a" in s True >>> "ac" in s False >>> # ac is not a substring of s. >>> [216.3, 216.3] in levels False >>> # no sublist checking >>> crazy = [1,2,3,[1,2,3]] >>> crazy [1, 2, 3, [1, 2, 3]] >>> len(crazy) 4 >>> crazy[3] [1, 2, 3] >>> crazy[3][1] 2 >>> ## numerical list functions >>> sum(levels) 6726.400000000001 >>> sum(levels)/len(levels) 216.98064516129034 >>> max(levels) 218.5 >>> min(levels) 214.6 >>> levels[5:10] [218.4, 218.3, 218.1, 217.9, 217.8] >>> ## lists are MUTABLE >>> >>> x = [1,2,3,4,5] >>> x [1, 2, 3, 4, 5] >>> x[0] = 10 >>> x [10, 2, 3, 4, 5] >>> # entries in a list are lvalues (left-hand assignment) >>> y = x >>> y [10, 2, 3, 4, 5] >>> x [10, 2, 3, 4, 5] >>> x[3] = -1 >>> x [10, 2, 3, -1, 5] >>> y [10, 2, 3, -1, 5] >>> # Rosemary Woods: Richard Nixon's secretary >>> x [10, 2, 3, -1, 5] >>> x[2:4] = [] >>> x [10, 2, 5] >>> x[2:3] = [10, 20, 30, 40, 50] >>> x [10, 2, 10, 20, 30, 40, 50] >>> #I can splice and slice >>> >>> type(x) >>> t = (1,2,3,4,5) >>> type(t) >>> t[0] 1 >>> t[3:] (4, 5) >>> t (1, 2, 3, 4, 5) >>> t[0] = 10 Traceback (most recent call last): File "", line 1, in TypeError: 'tuple' object does not support item assignment >>> x = [1,2,3,4] >>> t = (1,2,3,4) >>> id(x) 4313812416 >>> x += [5,6,7] >>> id(x) 4313812416 >>> id(t) 4313036368 >>> t += (5,6,7) >>> t (1, 2, 3, 4, 5, 6, 7) >>> id(t) 4312346400 >>> #relatonal operators???? >>> >>> eclectic = [1, "cow", 4.5, True, ["a", "b", "c"]] >>> # list is a heterogeneous sequence type >>> # list is mutable >>> # tuple is a heterogeneous immutable sequence type >>> >>> ## strings and relationals >>> "abc" < "abd" True >>> "XYZ" < "abc" True >>> "123" < "11" False >>> "52" < "10001" False >>> "Cowabunga" < "aardvark" True >>> "1" < "a" True >>> ";" < ":" False >>> ## upper case < lower case >>> ## digits < lower case >>> ord("a") 97 >>> ord(";") 59 >>> ord("A") 65 >>> "Aardvark" < "Aardwolf File "", line 1 "Aardvark" < "Aardwolf ^ SyntaxError: unterminated string literal (detected at line 1) >>> "Aardvark" < "Aardwolf" True >>> "Aardvark" < "AardWolf" False >>> bin("a") Traceback (most recent call last): File "", line 1, in TypeError: 'str' object cannot be interpreted as an integer >>> bin(ord("a")) '0b1100001' >>> bin(ord("A")) '0b1000001' >>> ^D MAC:Thu Feb 10:11:22:~> vi sampler.txt MAC:Thu Feb 10:11:23:~> xxd -b sampler.txt bin.txt MAC:Thu Feb 10:11:23:~> vi bin.txt MAC:Thu Feb 10:11:27:~> python Python 3.10.0 (v3.10.0:b494f5935c, Oct 4 2021, 14:59:19) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> x = "Abacus" >>> y = "bubblehead" >>> x < y True >>> x = "abacus" >>> y = "Bubblehead" >>> x < y False >>> x.upper() < y.upper() True >>> x.lower() < y.lower() True >>> "52" > "10001" True >>> "type determines context" 'type determines context' >>> bool([]) False >>> bool([3,2,2]) True >>> ## truthiness: an object is truthy if casts as a boolean to True >>> ## falsiness: falsy if it cast as a boolean to false >>> >>> bool(0) False >>> bool(0.0) False >>> bool("") False >>> bool([]) False >>> bool((,)) File "", line 1 bool((,)) ^ SyntaxError: invalid syntax >>> bool((4,)) True >>> x = (4,) >>> x (4,) >>> x = [3,1,6,8,4] >>> sorted(x) [1, 3, 4, 6, 8] >>> x [3, 1, 6, 8, 4] >>> x = ["a", True, 5] >>> sorted(x) Traceback (most recent call last): File "", line 1, in TypeError: '<' not supported between instances of 'bool' and 'str' >>> x = [3, 1.4, 9, 6.02e23, 1e-6] >>> x [3, 1.4, 9, 6.02e+23, 1e-06] >>> sorted(x) [1e-06, 1.4, 3, 9, 6.02e+23] >>> x.sort(0 ... ) Traceback (most recent call last): File "", line 1, in TypeError: sort() takes no positional arguments >>> x.sort() >>> x [1e-06, 1.4, 3, 9, 6.02e+23] >>>