Shortest way to get a TypeError

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.

• this isn't really defined for other languages. You've also immediately answered the shortest possible way for Python... – Jo King Jul 31 at 2:29
• @JoKing I answer one out of 3 or more, feel free to post the other 3 byte ones – U10-Forward Jul 31 at 2:30
• This shouldn't be closed, but it's only well-defined for one language (Python) – MilkyWay90 Jul 31 at 2:31
• I'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 Jul 31 at 2:37
• Oh right, you might want to post your challenges to the Sandbox before you post this here. – A _ Jul 31 at 3:27

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


Try it online!

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:

1. Math operator, non-numeric types

• Math operator including +, -, ~
• Non-numeric types including "", (), [], id, {}
+[]
-""
~id

2. Invoke number as function

0()


3. Matrix multiplication between numbers

@ is __matmul__ in python, read more here

0@0


4. Binary operator with float / complex number

~0.
~.0
~0j


5. Iterate over number

Thanks to @Dennis to point out this.

You may iterate some variable by star operator. And () for a tuple may be omitted.

*0,


Python 3, 3 bytes

+''


Try it online!

• Uh oh. I can not make my program less than 3 bytes. Anyway, nice trick! – A _ Jul 31 at 2:31
• @A__ Yeah, anyway you can post the other 3 byte ones – U10-Forward Jul 31 at 2:31

Python, 3 bytes

This is self-explanatory. The unary - operator does not take a string argument. This was covered in @tsh's solution above.

-""


Try it online!

Another one:

~id


Try it online!

• Haha yeah nice idea i still have more than 2 different styles in mind tho – U10-Forward Jul 31 at 2:35
• yeah, double quotes and that's about it – Jo King Jul 31 at 2:36
• There is also -id and +id – Jo King Jul 31 at 2:38

JavaScript (V8), 4 bytes

1.()


Try it online!

[Output]

.code.tio:1: TypeError: 1 is not a function 1.() ^ TypeError: 1 is not a function at .code.tio:1:3