THIS Is A Crazy Way To Handle Types In Python

preview_player
Показать описание
This is a crazy way to handle types in Python. #code #python #programming
Рекомендации по теме
Комментарии
Автор

type() **exists**

_why am i still here. Just to suffer.._

RiseofDevil
Автор

Type(var) or even var.__class__ seems easier

DrDeuteron
Автор

Match case only works if you have Python 3.10 or higher

Kakashi
Автор

you can use type() no more bhadak... btw nice knowledge❤

CodeZeroSix
Автор

This is just for showing the new feature in python, so don't complain that type() can do it simpler.

yekhtiari
Автор

A type can be anything though, it could be a list of objects, it could be mysterious Python object... And anyway you can use type()

alkebabish
Автор

When would you need this over type(var)

jeffreyepiscopo
Автор

What about if it’s like classes, or large and compact forms of data?

KeiraraVT
Автор

Is there a case when isinstance() would not give the result of this match?

ethanfrink
Автор

if type(var) == str: or match type(var): case str:

miguelxd
Автор

You can use type brother to do that easily

creativeimg
Автор

e.g; convert_it(some_data, demo_type), where match checks demo_type and converts some_data to that type, demo_type was chosen by the user, combined with custom types ...

jyvben
Автор

Why would you use that over isisnstance()

vi_k
Автор

type(var), var._class_, isinstance() and *is* operator: Are we jokes for you?

robertobokarev
Автор

If you find yourself doing this and it's actually necessary, stop immediately and go fix whatever you did wrong somewhere else that made this necessary.

DustinSummy
Автор

Isn't calling it a constructor correct? Aren't data types in Python an object?

AntonioZL
Автор

Why is this better than using if sld elif stements?

karag
Автор

Suggestion: Do this example again but use Single Dispatch ...

apmcd
Автор

And if any of your types are subclassed, that won't work, which is why you're supposed to use isinstance instead.

tommywareing
Автор

this is pretty interesting but why tf would it work like this?

schlopping