Last login: Fri Aug 20 08:08:31 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. (base) MAC:Fri Aug 20:14:00:~> 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 + 6 8 >>> 2 - 6 -4 >>> 2*6 12 >>> 2/6 0.3333333333333333 >>> 2//6 0 >>> 365//7 52 >>> 365 % 7 1 >>> 2**1000 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376 >>> len(str(2**1000)) 302 >>> 44^5 41 >>> type(3) <class 'int'> >>> type(.33) <class 'float'> >>> ## IEEE 754 >>> # floats are 64 bit (double precision) floating point numbers >>> .1 + .1 + .1 == .3 False >>> .1 + .1 + .1 0.30000000000000004 >>> 6.02e32 6.02e+32 >>> type(6.02e23) <class 'float'> >>> 3E8 300000000.0 >>> >>> >>> int(4.5) 4 >>> # a cast is a temporary request to regard an object of one type as beig of another >>> # it does not change the originial object >>> str(5 + 6) '11' >>> float(4) 4.0 >>> z = complex(1,2) >>> z**10 (237-3116j) >>> # first character is alpha or _ >>> # subsequent characters are alphanumeric or _ >>> # number_of_snakes this is snake notation >>> x = 5 >>> type(x) <class 'int'> >>> x = "cowabungazungablurb" >>> type(x) <class 'str'> >>> type(heffalump) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'heffalump' is not defined >>> 4 < 5 True >>> type(4 < 5) <class 'bool'> >>> 4 <= 5 True >>> 4 >= 5 False >>> 4 > 5 False >>> 4 == 5 False >>> 4 != 5 True >>> not(True) False >>> not(False) True >>> not False True >>> #prefix unary operator >>> ## and, or are infix binary operators >>> True or False True >>> False or True True >>> True or True True >>> False or False False >>> True and True True >>> True and False False >>> False and True False >>> False and False False >>> x = "abcdefghijklmnopqrstuvwxyz" >>> x[1] 'b' >>> x[2] 'c' >>> x[3] 'd' >>> x[:5] 'abcde' >>> x[4:7] 'efg' >>> x[:4] + x[4:] 'abcdefghijklmnopqrstuvwxyz' >>> "cow" + "pie" 'cowpie' >>> ### TYPE DETERMINES CONTEXT >>> >>> "cow" + 42 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can only concatenate str (not "int") to str >>> a = "cow" >>> b = 42 >>> a + str(b) 'cow42' >>> f"{a}{b}" 'cow42' >>> x 'abcdefghijklmnopqrstuvwxyz' >>> x.upper() 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' >>> x 'abcdefghijklmnopqrstuvwxyz' >>> y = x.upper() >>> y 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' >>> y.lower() 'abcdefghijklmnopqrstuvwxyz' >>> x.find("j") 9 >>> pal = "amanaplanacanalpanama" >>> pal.find("p") 5 >>> pal.rfind("p") 15 >>> x[:x.find("o")] + x[x.find("o"):] 'abcdefghijklmnopqrstuvwxyz' >>> x[:x.find("o")] + x[x.find("o"):].upper Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can only concatenate str (not "builtin_function_or_method") to str >>> x[:x.find("o")] + x[x.find("o"):].upper() 'abcdefghijklmnOPQRSTUVWXYZ' >>> " I am a space cadet".replace(" ", "") 'Iamaspacecadet' >>> "My favorite class is math.".replace("math", "compsci") 'My favorite class is compsci.' >>>