package java; public class Print{ public static void main(String[] args){ System.out.println("Hello World!"); } }In Python, this task can be accomplished in only one line.
print("Hello World!")
Java | Python | |
---|---|---|
File Naming | Program.java | program.py |
Output | System.out.println("Hello World!"); | print("Hello World!") |
Variables | int x=5; String name="Mickey Engel"; |
x=5 name="Mickey Engel" |
Input | Scanner sc=new Scanner(System.in); name=sc.nextLine(); |
name=input("Enter your name:") |
Comments | //single line comment /* multi-line comment */ |
#single line comment """ multi-line comment """ |
Concatenation | "Hello, "+name; | "Hello, "+name |
Java | Python | |
---|---|---|
Importing | import java.util.Math; | import math |
Rounding | Math.floor(x); Math.ceil(x); Math.round(x); |
math.floor(x) math.ceil(x) math.round(x) |
Comparisons | Math.max(x,y); Math.min(x,y); |
min(x,y) max(x,y) |
Powers | Math.pow(x,y); Math.sqrt(x); |
pow(x,y); math.sqrt(x) |
PI | Math.PI | math.pi() |
Case Conversions | str.toUpperCase(); str.toLowerCase(); |
str.upper() str.lower() |
String Length | str.length(); | len(str) |
Substrings | str.substring(start, end); | str[start, end] |