The list of key differences that should help a Java guy to get Python faster and with no stress.
- 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.
- 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.
- You can do pure functional programming.
- You declare class A that extends class B like this: class A(somepackage.B).
- Can't add an int to a string like you'd do in Java. int needs to be converted into string: str(10).
- Functions are objects, you can pass one function to another one.
- Double quotes are the same as single quotes.
- Python has some built-in functions like str(), type(). Really, stop thinking in classes.
- self = this, it gets passed as the first argument in functions.
- You can pass args to functions in random order, specifying variable name.
- Function args can have default values.
- 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.
- None = null.
- Functions can return multiple values (aka tuples).
- In Java, you have static, Python has staticmethods and classmethods. The latter does preserve context.
- 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.
- Decorators are a powerful feature, e.g. annotating a method with @property would allow access the result it returns like a usual property.