Appendix E. Java-to-Python Quick Reference
This is a quick reference guide to the syntactic differences between Java and Python. It is not intended to provide full information on semantic differences between the two languages.
Basic Data Types
Python has a more limited set of numerical types than Java, but otherwise the two languages are similar. Python does not perform automatic conversions between types, however each basic type has a built-in function of the same name that attempts to convert the argument to that type.
Java | Python | Comment |
| Python has no specific
Boolean type. False is represented by | |
|
| A character is just a
string of length |
|
| |
|
| A Python long has unbounded length. |
|
| Python floats have the same width as Java doubles. |
Advanced Data Types
Python’s more advanced built-in types have more functionality and flexibility built into them than their Java equivalents.
Java | Python | Comment |
|
| |
|
| |
|
| |
|
| Python files contain much of the functionality of Java I/O streams. |
Logical Operators
Python tends to use English words for its logical operators rather
than symbols. Python has no equivalent to the Java operators
^
(binary XOR) and ?:
(ternary
conditional operator).
Java | Python | Comment |
|
| Python operator always short circuits. |
|
| Python operator always short circuits. |
|
| |
|
| Test for identical object identity. |
|
Get Jython Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.