Java to Python: the different parts

The list of key differences that should help a Java guy to get Python faster and with no stress.

  1. Declaring a variable, you don't specify it's type; moreover, a variable that now points to a string, can be reassigned to an integer.
  2. Python has a different take on classes and packages than Java. The rule "file = class" doesn't apply. Modules are to Python what packages are to Java. Module name consists of folder name(s) and file name. A folder must contain a special file __init__.py in it to be a package. That file can have functions and classes in it as well.
  3. You can do pure functional programming.
  4. You declare class A that extends class B like this: class A(somepackage.B).
  5. Can't add an int to a string like you'd do in Java. int needs to be converted into string: str(10).
  6. Functions are objects, you can pass one function to another one.
  7. Double quotes are the same as single quotes.
  8. Python has some built-in functions like str(), type(). Really, stop thinking in classes.
  9. self = this, it gets passed as the first argument in functions.
  10. You can pass args to functions in random order, specifying variable name.
  11. Function args can have default values.
  12. You are not limited to declaring imports at the beginning of the file, might declare right in a function. This could make sense performance-wise.
  13. None = null.
  14. Functions can return multiple values (aka tuples).
  15. In Java, you have static, Python has staticmethods and classmethods. The latter does preserve context.
  16. In Java, you declare a private variable thats accessible via public methods. In Python, you access a variable directly and optionally declare setter & getter methods that will be automatically called.
  17. Decorators are a powerful feature, e.g. annotating a method with @property would allow access the result it returns like a usual property.