How do I define a custom literal in Python? For example, type (37C) ==<class 'temp'>

Question:

Can I create my own class / type with my own syntax?

For instance:

mycar = bmw 
# или
mytemp = 37C

print(type(mycar))

print(type(mytemp))

For the answer to be like this:

<class 'car'> 
# или
<class 'temp'>

Not like this:

SyntaxError: invalid syntax

Answer:

Of course you can, read about OOP in Python. This can be done using classes. If you're talking about custom literals, they haven't been introduced yet, but they are often suggested.

Scroll to Top