Java/C#/Python基本语法区别
一、代码格式
Python:一句程序结束不用分号结束“;”,用缩进来表示语句块
Java/C#:使用分号结束“;”,使用花括号来表示语句块
二、注释
Python:单行注释使用“#”,多行注释使用“’’’”,快捷键使用“Ctrl+/”
Java:单行注释使用“//”,多行注释使用“/* /”
C#:单行注释使用“//”,多行注释使用“/ */”,文档注释使用 “///”
三、输出打印
Python:print(“The length of %s is %d” % (s, n)) #格式化输出
Java:System.out.printf(“%tF%n”,date); //2020-06-30
C#:Console.WriteLine(string.Format("{0:F}", System.DateTime.Now));//2017年8月24日 19:36:13
四、数据类型
1、Python
(1)整数
x=5 y=2 z=x+y print(z)
(2)浮点数
x=5.3 y=2.1 z=x+y print(z)
(3)字符串
str='hello’ print(str)
(4)转义字符
print(“hello \nbaidu”) 换行
print(‘c:\python35’) c盘下的python35文件夹
print(‘my name is ‘jack’ and “you”’) my name is ‘jack’ and “you”
(5)布尔值
t=True f=False print(t and f)
2、Java
(1)内置数据类型
①整型:byte 、short 、 int 、 long
byte b=100; short s=1000; int i=100000; long l=100000L;
②浮点型:float 、double
float f=1.5f; double d=2.55;
③字符型:char
char c=‘女’;
④布尔型:boolean
boolean b=true;
(2)引用数据类型
类(class)、接口(interface)、数组、String s=“字符串”;
3、C#
(1)值类型
①整型:byte、short、int、long
②浮点型:float(单精度)、double(双精度)
③Decimal类型:decimal 精度十进制类型
decimal d=12.30M
④布尔类型:bool
⑤字符类型:char
⑥枚举类型:Enum
enum sex{
man,woman,
}
⑦结构类型:Struct
struct student{
public int score;
public string name;
}
(2)引用类型
①数组:int []score=new int[]{89,79,60}
②类:class
③接口:interface
public interface Myinterface{
void fun();
}
④委托:delegate
public delegate void MyMultiDelegate(int value);
public class Publisher//事件发布者{
void Fun1(int a) {
}
void Fun2(int a) {
}
void<