Загрузка...

Python Trick Every Developer Should Know 🐍#shortsfeed #python #shorts

Python: simple things that improve code

If you write like this:

if type(x) == str:
    print("This is a string")
it might work, but it breaks on subclasses of str.

It's better to use isinstance(). It takes into account inheritance and is more consistent with polymorphism.

if isinstance(x, str):
    print("This is a string")
This variant will work for str and its subclasses.

Conclusion: type(x) == str is only suitable for simple cases, but it's fragile. isinstance(x, str) is a more stable and correct option almost always.

Subscribe for more @CodingWithMee_18

#python #coding #programming #pythonmemes #developer #pythondeveloper #learnpython #codememe #softwareengineer #tech #programmer #codinglife #debugging #100DaysOfCode

Видео Python Trick Every Developer Should Know 🐍#shortsfeed #python #shorts канала CodingWithMee
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять