How to define if nested in Python?