0% found this document useful (0 votes)
10 views1 page

Java vs Python Syntax Comparison Guide

The document provides a comparison chart of Java and Python syntax across various programming concepts. It highlights differences in print output, comments, variable declaration, control structures, loops, data structures, functions, classes, and exception handling. Each concept is illustrated with corresponding syntax examples for both languages.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Java vs Python Syntax Comparison Guide

The document provides a comparison chart of Java and Python syntax across various programming concepts. It highlights differences in print output, comments, variable declaration, control structures, loops, data structures, functions, classes, and exception handling. Each concept is illustrated with corresponding syntax examples for both languages.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java vs Python – Syntax Comparison Chart

Concept Java Syntax Python Syntax


Print Output [Link]("Hello"); print("Hello")
Comments // single-line /* multi-line */ # single-line """multi-line"""
Variable int x = 10; x = 10
Declaration
Input Scanner sc = new Scanner([Link]); int x = int(input())
x = [Link]();
If Condition if(x > 0) { } else { } if x > 0: ... else: ...
Else-if else if(x > 5) elif x > 5:
Switch Case switch(x) { case 1: ... } match x: case 1: ...
For Loop for(int i=0; i<5; i++) for i in range(5):
While Loop while(x < 5) { } while x < 5:
Array/List int arr[] = {1,2,3}; arr = [1,2,3]
String String s = "Hello"; s = "Hello"
Length [Link]() len(s)
Function/Method int add(int a,int b){ return a+b; } def add(a,b): return a+b
Class class A { } class A:
Object Creation A obj = new A(); obj = A()
Constructor A(){ } def __init__(self):
Inheritance class B extends A class B(A):
Exception try { } catch(Exception e){ } try: ... except Exception as e:
Handling
Import Package import [Link].*; import math

You might also like