Skip to content

Instantly share code, notes, and snippets.

@serafdev
Created July 27, 2022 18:04
Show Gist options
  • Save serafdev/50f60aa3e255d70bda0255fac2d53196 to your computer and use it in GitHub Desktop.
Save serafdev/50f60aa3e255d70bda0255fac2d53196 to your computer and use it in GitHub Desktop.
Collection as Parameter - Python
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