-4
1
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.
-4
1
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.
13
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,
2
1Uh oh. I can not make my program less than 3 bytes. Anyway, nice trick! – None – 2019-07-31T02:31:05.020
@A__ Yeah, anyway you can post the other 3 byte ones – U10-Forward – 2019-07-31T02:31:49.820
2
This is self-explanatory. The unary - operator does not take a string argument. This was covered in @tsh's solution above.
-""
Another one:
~id
Haha yeah nice idea i still have more than 2 different styles in mind tho – U10-Forward – 2019-07-31T02:35:28.247
yeah, double quotes and that's about it – Jo King – 2019-07-31T02:36:01.170
2
1.()
.code.tio:1: TypeError: 1 is not a function
1.()
^
TypeError: 1 is not a function
at .code.tio:1:3
1this isn't really defined for other languages. You've also immediately answered the shortest possible way for Python... – Jo King – 2019-07-31T02:29:43.530
@JoKing I answer one out of 3 or more, feel free to post the other 3 byte ones – U10-Forward – 2019-07-31T02:30:39.763
1This shouldn't be closed, but it's only well-defined for one language (Python) – MilkyWay90 – 2019-07-31T02:31:54.703
I now made this a python golf – U10-Forward – 2019-07-31T02:32:47.863
6I'm retracting my close vote, since this is pretty clear. But I'm downvoting this because it is an extremely simple challenge with an obvious optimal answer with no possibility of improvement. – Jo King – 2019-07-31T02:37:56.007
2
Oh right, you might want to post your challenges to the Sandbox before you post this here.
– None – 2019-07-31T03:27:10.713maybe add the
tips
tag since it's language-specific. – Giuseppe – 2019-07-31T13:19:11.513