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/lists_3.py at main · thomasWeise/programmingWithPythonCode Expand file tree/ Copy pathlists_3.pyMore file actions 26 lines (19 loc) · 1.1 KB / Copy pathlists_3.pyFile metadata and controls26 lines (19 loc) · 1.1 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 """An example of more operations with lists.""" lst1: list[int] = [1, 2, 3, 4] # create first list lst2: list[int] = [5, 6, 7] # create second list lst3: list[int] = lst1 + lst2 # lst3 = concatenation of lst1 and lst2. print(f"lst3 = lst1 + lst2 == {lst3}") # [1, 2, 3, 4, 5, 6, 7] lst4: list[int] = lst2 * 3 # lst4 = lst2, repeated three times. print(f"lst4 = lst2 * 3 == {lst4}") # [5, 6, 7, 5, 6, 7, 5, 6, 7] lst5: list[int] = lst4[2:-2] # lst5 = lst4 from index 2 to 3rd from end print(f"lst5 = lst4[2:-2] == {lst5}") # [7, 5, 6, 7, 5] lst6: list[int] = lst4[1::2] # start at index 1, take every 2nd element print(f"lst6 = lst4[1::2] == {lst6}") # [6, 5, 7, 6] # Start copying lst4 at last element, move backwards take every 2nd # element, and stop right before index=3. lst7: list[int] = lst4[-1:3:-2] print(f"lst7 = lst4[-1:3:-2] == {lst7}") # [7, 5, 6] lst7[1] = 12 # Modify the slice lst7 originally from lst4. print(f"{lst4 = }, {lst7 = }") # Shows that lst4 remains unchanged. a, b, c = lst2 # store the three elements of lst2 into variables print(f"{a = }, {b = }, {c = }") # a=5, b=6, c=7 |
| 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. |