Java | C# | Python |
---|---|---|
Comments | ||
Single line: // | // | # |
Multiple lines: /* */ | /* */ | " " " " " " (or) ' ' ' ' ' ' |
Data Types | ||
int | int | Python supports all the data types but we did not specify the type of the variable. The Python interpreter will automatically interpret the variable type. Eg: a = 10 b = "Testing" |
float | float | |
double | double | |
char | char | |
var | var | |
boolean | bool | |
String | string | |
etc., | ||
Input and Output | ||
System.out.print("string"); | Console.Write("string"); | print("string") |
System.out.println("string"); | Console.WriteLine("string"); | |
Scanner obj = new Scanner(System.in); String name = obj.nextLine(); |
string name = Console.ReadLine(); | name = input() or name = input("Enter your name") |
nextInt(), nextFloat(), nextDouble(), nextBoolean(), nextLine(), ------- | --------- | int(input()), float(input()), complex(input()) |
Operators | ||
Arithmetic : +, -, *, /, %, ++, --, +=, -=, *=, /=, %= | ++, -- are not work | |
Bitwise : ~, &, |, ^, >>, >>>, <<, &=, |=, ^=, >>=, >>>=, <<= | ||
Relatinal : ==, !=, >, <, >=, <= | ||
Boolean Logical : &, |, ^, ||, &&, !, &=, |=, ^=, ==, !=, ?: | ||
Java | C# | Python |
Control Statements | ||
Decision-Making statements | ||
if(condition) { Statements; } |
if(condition) { Statements; } |
if condition : Statement1 Statemnet2 |
if(condition1) { Statements; } else if(condition2) { Statements; } else { Statements; } |
if(condition1) { Statements; } else if(condition2) { Statements; } else { Statement; } |
if condition1 : Statements elif condition2 : Statements else : Statements |
switch(expression){ case value1: Statement 1; break; ------ default: Statement; } |
switch(expression){ case value1: Statement 1; break; ------ default: Statement; } |
Python does not support switch case statements. |
Loop statements | ||
for(initialization; condition; increment/decrement) { Statement; } |
for(initialization; condition; increment/decrement) { Statement; } |
for variable in sequence : Statements |
for(data type variable : array_name/collection_name) |
foreach(data type
variable
in
array_name/collection_name) |
|
while(condition){ Statements;} |
while(condition){ Statements;} |
while condition : Statements |
do { Statement; }while(condition) |
do { Statement; }while(condition) |
Python does not support do-while statements. |
Jump statements | ||
break; | break; | break |
continue; | continue; | continue |
--- | --- | pass |
Java | C# | Python |
---|---|---|
Array | ||
Array declaration | Python does not support Arrays. but Python Lists can be used instead of Arrays. |
|
int[] a; int a[]; int []a; |
int[] a; | |
int[][] a; int [][]a; int[] a[]; int[] []a; int []a[]; |
int[][] a; | |
Array Construction | ||
int[] a = new int[5]; | int[] a = new int[5]; | |
int[][] a = new int[3][2]; | int[][] a = new int[3][2]; | |
int[] a = {1, 2, 3, 4, 5, ---} | int[] a = {1, 2, 3, 4, 5, ---} | |
Java | C# | Python |
String Method | ||
charAt(index) | [index] | |
String length: length() Array length: length |
Length | |
str1.equals(str2) | String.Equals(str1, str2) | |
indexOf(String) | IndexOf(string) | |
replace('x', 'y') | Replace('x', 'y') | |
split() | Split() | |
toUpperCase() | ToUpper() | |
toLowerCase() | ToLower() | |
compareTo() | Compare() | |
contains() | Contains() | |
. | . | |
. | . |
Java | C# | Python |
---|---|---|
List / IList | ||
List | IList | |
ArrayList |
|
|
Vector |
|
|
Stack |
|
|
LinkedList |
|
|
Set / ISet | ||
|
|
|
|
|
|
|
|
|
Java | C# | |
HashMap | ||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List / IList | ||
|
|
|
|
|
|
|
|
No comments:
Post a Comment