Intro to Python
a day ago
- Python variables do not require explicit types, unlike Java where types must be declared (e.g., `i = 1` vs `int i = 1`).
- Python supports dynamic typing and duck-typing, allowing lists to hold mixed types (e.g., `l = [1, 1.2, 'hello, world']`), while Java requires generics or explicit typing.
- Python dictionaries can use non-integer keys (e.g., `{'Monday': 'MATH 374'}`), and indexing works similarly to lists.
- Python uses `**kwargs` to handle arbitrary keyword arguments in functions, whereas Java uses varargs with a functional interface like `IntConsumer`.
- Python's documentation uses triple-quoted strings with plain text, while Java's Javadoc uses `/** */` with HTML markup.
- Python's `print` function can be redefined to accept variable arguments using `*args`, similar to Java's varargs with `Object...`.
- Python supports lambda functions and higher-order functions (e.g., `call_with_one(lambda arg: print(arg))`) more syntactically flexibly than Java, which requires functional interfaces.