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_2.py at main · thomasWeise/programmingWithPythonCode Expand file tree/ Copy pathlists_2.pyMore file actions 30 lines (22 loc) · 1.45 KB / Copy pathlists_2.pyFile metadata and controls30 lines (22 loc) · 1.45 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 27 28 29 30 """An example of creating, modifying, sorting, and copying lists.""" numbers: list[int] = [1, 7, 56, 2, 4] # Create the list. print(f"The numbers are: {numbers}.") # Print the list. print(f"is 7 in the list: {7 in numbers}") # Check if 7 is in the list. print(f"is 2 NOT in the list: {2 not in numbers}") # the opposite check print(f"7 ist at index {numbers.index(7)}.") # Search for number 7. print(f"2 ist at index {numbers.index(2)}.") # Search for number 2. numbers.insert(2, 12) # Insert the number 12 at index 2... print(f"After inserting 12, the numbers are: {numbers}.") # and print. numbers.remove(56) # Remove the number 56 from the list. print(f"After removing 56, numbers are: {numbers}.") # Print the list. numbers.sort() # Sort the list `numbers` in place. print(f"The sorted numbers are: {numbers}.") # Print the list. numbers.reverse() # Reverse the order of the list elements. print(f"The reversed numbers are: {numbers}.") # And print the list. cpy: list[int] = list(numbers) # Create a copy of the list `numbers`. print(f"cpy == numbers: {cpy == numbers}.") # Indeed, `cpy == numbers`. print(f"cpy is numbers: {cpy is numbers}.") # No, `cpy is not numbers`. del cpy[0] # We change `cpy`, but `numbers` remains unchanged. print(f"cpy == numbers: {cpy == numbers}.") # Now, `cpy != numbers`. print(f"cpy is numbers: {cpy is numbers}.") # And `cpy is not numbers`. print(f"cpy is not numbers: {cpy is not numbers}.") # indeed, it is not |
| 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. |