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. >>> "a" < "b" True >>> "a" < "Z" False >>> ord("a") 97 >>> chr(97) 'a' >>> bin(chr("a")) Traceback (most recent call last): File "", line 1, in TypeError: an integer is required (got type str) >>> bin(ord("a")) '0b1100001' >>> bin(ord("A")) '0b1000001' >>> #every character has a byte value >>> ord("0") 48 >>> "cereal" < "cerebral" True >>> #dictioanry ordering based on ASCII value >>> #asciicographical ordering >>> "45" < "9" True >>> x = "Smith" >>> y = "jones" >>> x < y True >>> x.upper() < y.upper() False >>> cow = 'elsie' >>> horse = "secretariat" >>> print('horse\'s petoot') horse's petoot >>> print("horse's petoot") horse's petoot >>> x = "a\tb\nc\n\n" >>> x 'a\tb\nc\n\n' >>> print(x) a b c >>> print("\\") \ >>> #Let's get raw >>> print(r"\\n") \\n >>> #raw string: whack's magic gets whacked. >>> print("c:\cow\bill gates\nuts") c:\coill gates uts >>> print(r"c:\cow\bill gates\nuts") c:\cow\bill gates\nuts >>> print("""This goes on ... for many lines ... until we are all asleep""") This goes on for many lines until we are all asleep >>> print('''bleep ... blap ... bomba''') bleep blap bomba >>> x = 5 >>> y = 2 >>> print(f"{x} + {y} = {x + y}") 5 + 2 = 7 >>> print(str(x) + " + " + str(y) + " = " + str(x + y)) 5 + 2 = 7 >>> for k in range(10): ... print(f"{k}{k*k}") ... 00 11 24 39 416 525 636 749 864 981 >>> x 5 >>> y 2 >>> print(f"{x} < {y} is {x < y}") 5 < 2 is False >>> >>> "%s + %s = %s".format(x, y, x + y) '%s + %s = %s' >>> "{} + {} = {}".format(x, y, x + y) '5 + 2 = 7' >>> "%s + %s = %s" % (x, y, x + y) '5 + 2 = 7' >>> x = [1,2,3,4,5] >>> type(x) >>> print(x[0]) 1 >>> list("cows") ['c', 'o', 'w', 's'] >>> str(x) '[1, 2, 3, 4, 5]' >>> def f(x): return x*x ... >>> type(f) >>> str(f) '' >>> x[1:] [2, 3, 4, 5] >>> x[1:3] [2, 3] >>> x[::2] [1, 3, 5] >>> x[1::2] [2, 4] >>> len("dsfewwee") 8 >>> len(x) 5 >>> menagerie = [2, True, "cow", [1,2,3], 5.6, f] >>> print(menagerie) [2, True, 'cow', [1, 2, 3], 5.6, ] >>> menagerie[5](10) 100 >>> menagerie[0] 2 >>> menagerie[3][1] 2 >>> menagerie[3][2] 3 >>> x [1, 2, 3, 4, 5] >>> x[6] Traceback (most recent call last): File "", line 1, in IndexError: list index out of range >>> x[0] = 6 >>> x [6, 2, 3, 4, 5] >>>