Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Data Type in Python which cannot be typecast in string

Lets say 'a' is of some type (which I want to know!)

Doing a thing like:

b = str(a)

This should favorably raise a TypeError

like image 487
hyades Avatar asked Sep 14 '26 20:09

hyades


1 Answers

There is no builtin Python class that raises a TypeError with str, but you could define a custom class:

class Foo(object):
    def __str__(self):
        raise TypeError('Can not by stringified')


foo = Foo()
b = str(foo)

raises a TypeError.

like image 133
unutbu Avatar answered Sep 16 '26 10:09

unutbu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!