Skip to content

Instantly share code, notes, and snippets.

@serafdev
Created July 27, 2022 18:04

Revisions

  1. serafdev created this gist Jul 27, 2022.
    25 changes: 25 additions & 0 deletions collection_as_param.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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]
    """