Python :
- The Variables do not need type declarations.
x = 10 # no type declaration needed
x = "hello" # can reassign to a different type
- The syntax uses indentation for code blocks.
def print():
a=10
print("Hello, World!")
- Python supports standalone functions outside classes.
def greet(name):
return f"Hi {name}"
Java :
- The java is strictly declare the data type before you create a variable.
int x = 10; // type must be declared
// x = "hello"; // compile error!
- The Java uses curly braces .
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
- Java requires everything to be inside a class — no standalone functions
public class Greeter {
public static String greet(String name) {
return "Hi " + name;
}
}
Top comments (0)