It's simple, simply write the shortest code to raise a TypeError
.
In Python you can do:
raise TypeError
However it should be shorter with a code that gives a TypeError
without raising it.
It's simple, simply write the shortest code to raise a TypeError
.
In Python you can do:
raise TypeError
However it should be shorter with a code that gives a TypeError
without raising it.
for chr1 in range(32, 128):
for chr2 in range(32, 128):
for chr3 in range(32, 128):
code = chr(chr1) + chr(chr2) + chr(chr3)
try:
output = exec(code, {})
except TypeError:
print(code)
except:
pass
A naive search may result that you cannot trigger a TypeError within 2 characters. You may get a TypeError with 3 characters. All solutions including:
+
, -
, ~
""
, ()
, []
, id
, {}
+[] -"" ~id
0()
@
is __matmul__
in python, read more here
0@0
~0.
~.0
~0j
Thanks to @Dennis to point out this.
You may iterate some variable by star operator. And ()
for a tuple may be omitted.
*0,
1.()
.code.tio:1: TypeError: 1 is not a function
1.()
^
TypeError: 1 is not a function
at .code.tio:1:3
This is self-explanatory. The unary - operator does not take a string argument. This was covered in @tsh's solution above.
-""
Another one:
~id
+[]
It gives an TypeError: bad operand type for unary +: 'list
exec
s that, and no two bytes raised a TypeError
. Therefore, raising an TypeError
with less than three bytes is impossible.
\$\endgroup\$