python type(x).__name__ vs x.__class__.__name__ (intermediate) anthony explains

Поділитися
Вставка
  • Опубліковано 22 жов 2024

КОМЕНТАРІ • 2

  • @dom1310df
    @dom1310df 4 роки тому +2

    Is the different behaviour with Python 2's old style classes the reason PEP 8 recommends against doing "type(obj) is type(1)" and instead doing "isinstance(obj, int)"?

    • @anthonywritescode
      @anthonywritescode  4 роки тому +4

      the reason the PEP recommends against type(...) checks directly is more for inheritance (if someone extends a class the type check no longer passes) -- though sometimes you want an exact check