GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — programmingWithPythonCode/collections/tuples_2.py at main · thomasWeise/programmingWithPythonCode Expand file tree/ Copy pathtuples_2.pyMore file actions 20 lines (14 loc) · 776 Bytes / Copy pathtuples_2.pyFile metadata and controls20 lines (14 loc) · 776 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 """An example of creating tuples of mixed types.""" mixed: tuple[str, int, float] = ("apple", 12, 1e25) # mixed types print(f"The mixed tuple is {mixed}.") # Print the tuple. other: tuple[str, int, float] = ("pear", 1, 1.2) # second such tuple print(f"the other tuple: {other}.") # Print it as well. tuples: list[tuple[str, int, float]] = [ # Create a list of 4 tuples. mixed, ("pear", -2, 4.5), other, ("pear", -2, 3.3)] print(f"tuples list: {tuples}.") # Print that list. tuples.sort() # We sort the list of tuples. print(f"sorted tuples list: {tuples}.") a, b, c = mixed # We unpack the tuple of length 3 into 3 variables. print(f"{a = }, {b = }, {c = }") mixed = "x", 4, 4.5 # Declare a tuple without parentheses. print(f"mixed is now: {mixed}") |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |