• List vs tuple

    A list is mutable: you can add, remove or change items. A tuple is immutable. Tuples can be dictionary keys if their items are hashable.

    a = [1, 2]; a[0] = 9   # works
    b = (1, 2); b[0] = 9   # TypeError
  • Mutable default argument trap

    Default values are created once, when the function is defined, so a list default is shared between calls. Fix it by using None and creating a new list inside the function.

    def add(x, items=[]):
        items.append(x)
        return items
    add(1)  # [1]
    add(2)  # [1, 2]
  • == vs is

    == checks whether values are equal. is checks whether two names point to the same object. Use is only for None.

    a = [1, 2]
    b = [1, 2]
    a == b  # True
    a is b  # False
  • *args and **kwargs

    *args collects extra positional arguments into a tuple. **kwargs collects extra keyword arguments into a dict.

    def f(*args, **kwargs):
        print(args, kwargs)
    f(1, 2, name='Asha')
  • Practise on real roles

    Open today's verified openings, read the Python skills companies actually ask for, then pick one role and practise answering these for that exact job.

    hirastra.com/today

Skip the searching: today's verified openings are posted three times a day with official apply links, and you can check your resume against any of them with the free ATS checker.

Join on WhatsApp