Last login: Fri Aug 20 07:56:41 on ttys000 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 Aug 20:07:57:~> python Python 3.8.5 (default, Sep 4 2020, 02:22:02) [Clang 10.0.0 ] :: Anaconda, Inc. on darwin Type "help", "copyright", "credits" or "license" for more information. >>> 2 + 2 4 >>> 2 - 2 0 >>> 2*2 4 >>> 10 / 3 3.3333333333333335 >>> 10 // 3 3 >>> 10 % 3 1 >>> 2**5 32 >>> type(2) >>> 2**1000 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376 >>> 3^4 7 >>> type(3.3333333333333335) >>> # floats are IEEE double precision floating point numbers >>> .1 + .1 + .1 == .3 False >>> .1 +.1 + .1 0.30000000000000004 >>> 4e5 400000.0 >>> 4E5 400000.0 >>> 4 + .5 4.5 >>> int(4.5) 4 >>> int(-4.5) -4 >>> ## cast float to int results in truncation of decimal part >>> float(4) 4.0 >>> z = complex(3,4) >>> z (3+4j) >>> z**2 (-7+24j) >>> # variable name rule >>> # must start wiht alpha character or _ >>> # succeeding characters are alphanumeric or _ >>> number_of_snakes = 42 >>> type(number_of_snakes) >>> number_of_snakes = "caterwaul" >>> type(number_of_snakes) >>> 4 < 5 True >>> 5 < 4 False >>> type(True) >>> 4 == 5 False >>> ## isequalto operator. It is distinct from = which is assignment. >>> 5 = x File "", line 1 SyntaxError: cannot assign to literal >>> 4 <= 5 True >>> 4 >- File "", line 1 4 >- ^ SyntaxError: invalid syntax >>> 4 >= 5 False >>> 4 != 5 True >>> not(4 == 5) True >>> True or False True >>> True or True True >>> False or True True >>> False or False False >>> True and True True >>> True and False False >>> False and True False >>> False and False False >>> ## what is the order of operations? >>> >>> x = "abcdefghijklmnopqrstuvwxyz" >>> >>> x[1] 'b' >>> x[0] 'a' >>> type(x[1]) >>> x[1:4] 'bcd' >>> x[1:4] + x[4:6] 'bcdef' >>> # type determines context >>> # + adds numbers >>> # + concatenates sstrings >>> "cows" + 42 Traceback (most recent call last): File "", line 1, in TypeError: can only concatenate str (not "int") to str >>> a = "cows" >>> b = 42 >>> a + str(42) 'cows42' >>> f"{a}{b}" 'cows42' >>> x[1:6] 'bcdef' >>> x[4:] 'efghijklmnopqrstuvwxyz' >>> x[:4] 'abcd' >>> x[::2] 'acegikmoqsuwy' >>> x[::3] 'adgjmpsvy' >>> x[1::3] 'behknqtwz' >>> x[:13:3] 'adgjm' >>> x.upper() 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' >>> x 'abcdefghijklmnopqrstuvwxyz' >>> y = x.upper() >>> x 'abcdefghijklmnopqrstuvwxyz' >>> y 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' >>> y.lower() 'abcdefghijklmnopqrstuvwxyz' >>> "#$%$EWDFSAvdrjgi[jer0fdsgerv23454332423".lower >>> "#$%$EWDFSAvdrjgi[jer0fdsgerv23454332423".lower() '#$%$ewdfsavdrjgi[jer0fdsgerv23454332423' >>> x 'abcdefghijklmnopqrstuvwxyz' >>> q = x[0:x.find("m")] + x[x.find("m")]] File "", line 1 q = x[0:x.find("m")] + x[x.find("m")]] ^ SyntaxError: unmatched ']' >>> q = x[0:x.find("m")] + x[x.find("m")] >>> q 'abcdefghijklm' >>> q = x[0:x.find("m")] + x[x.find("m":)] File "", line 1 q = x[0:x.find("m")] + x[x.find("m":)] ^ SyntaxError: invalid syntax >>> q = x[0:x.find("m")] + x[x.find("m"):] >>> q 'abcdefghijklmnopqrstuvwxyz' >>> q = x[0:x.find("m")].upper() + x[x.find("m"):] >>> q 'ABCDEFGHIJKLmnopqrstuvwxyz' >>>