Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # < ==========================================
- # < Functions and Methods
- # < ==========================================
- def append(_list, item) -> None:
- """Method to add an item to a list"""
- # Built-in code goes here
- return None
- def double(number) -> int:
- """Function to double a number"""
- return number * 2
- # < ==========================================
- # < Test One
- # < ==========================================
- output = [double(i) for i in range(1, 11)]
- print(output)
- # output = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
- # The left side of double(i) for i in range(1, 11) is evaluated each time
- # Each item in the output list is evaluated to be the return of double(i), which returns an integer
- # < ==========================================
- # < Test Two
- # < ==========================================
- squares = []
- print(f"Squares list before running [squares.append(i * i) for i in range(1, 11)]: {squares}")
- # Squares list before running [squares.append(i * i) for i in range(1, 11)]: []
- output = [squares.append(i * i) for i in range(1, 11)]
- print(output)
- # output = [None, None, None, None, None, None, None, None, None, None]
- # The left side of squares.append(i * i) for i in range(1, 11) is evaluated each time
- # Each item in the output list is evaluated to be the return of squares.append(i * i), which returns None
- print(f"Squares list after running [squares.append(i * i) for i in range(1, 11)]: {squares}")
- # Squares list after running [squares.append(i * i) for i in range(1, 11)]: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Advertisement
Add Comment
Please, Sign In to add comment