A Quick Meditation on Types

By anders pearson 06 Jul 2013

This is valid Java:

public class Foo {
public static void main(String[] args) {
Integer i = 3;
System.out.println("i is: " + i);
}
}
view raw gistfile1.java hosted with ❤ by GitHub

But this is not valid Python:

i = 3
print "i is: " + i
# you get: TypeError: cannot concatenate 'str' and 'int' objects
view raw gistfile1.py hosted with ❤ by GitHub

It’s pretty easy to pick them apart and understand exactly why each is what it is, but I think it’s worth meditating on why it is somewhat surprising to most programmers.

Tags: programming java python types