Created
July 27, 2022 18:04
-
-
Save serafdev/50f60aa3e255d70bda0255fac2d53196 to your computer and use it in GitHub Desktop.
Collection as Parameter - Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List | |
import random | |
def f(x: List[int] = []) -> List[int]: | |
""" | |
Function that appends 1 random int to List x. | |
If no list is passed, returns a List with 1 element. | |
""" | |
x.append(random.randint(0, 100)) | |
return x | |
print(f()) | |
print(f()) | |
print(f()) | |
print(f()) | |
""" Returns: | |
[84] | |
[84, 70] | |
[84, 70, 1] | |
[84, 70, 1, 16] | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment