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)整数 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)
①整型: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;
类(class)、接口(interface)、数组、String s=“字符串”;
①整型: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; }
①数组: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 start(){ MyMultiDelegate mydelegate1 = new MyMultiDelegate (Fun1); MyMultiDelegate mydelegate2 = new MyMultiDelegate (Fun2); //组合多个委托方法 }}⑤字符串:string
1、Python:python并没有提供访问修饰符,python类中的所有成员都是公有的,我们可以在类外访问并进行修改。虽然python并没有严格意义上的受保护成员和私有成员,但是可以使用约定俗成的规则来区分: 受保护成员:_name=‘dog’ #注意:外部类仍然可以访问 私有成员:__name=‘cat’ #外部类可以通过object._class_variable的方式访问 2、Java:default(同一包内可见)、public(所有类可见)、private(同类可见)、protected(同一包内的类和子类可见) 3、C#:public(公有访问)、private(私有访问,只限于本类成员访问)、protected(保护访问,只限于本类和子类访问)、internal(内部访问,只限于本项目内访问)
1、Python:
score=70 if score>=80: print("A") elif score>=60: print("B") else: print("C")2、Java:
score=70; if(score>=80){ System.out.print (“A”) }else if (score>=60){ System.out.print(“B”) }else { System.out.print(“C”) }3、C#:
score=70; if(score>=80){ Console.WriteLine(“A”) }else if (score>=60){ Console.WriteLine(“B”) }else { Console.WriteLine(“C”) }1、Python:
sum=0 for i in range(11): sum=sum+i print(sum)2、Java:
int []numbers={10,20,30,40}; for(int i=0;i<=numbers.length;i++){ System.out.println(numbers[i]); } for(int x:numbers){ System.out.println(x); }3、C#:
int []numbers={10,20,30,40}; foreach(var item in numbers){ Console.WriteLine(item); }1、Python: 函数代码块以def关键词开头,后接函数名和圆括号() def max_num(a,b): #函数体 2、Java: 访问修饰符+返回值类型+方法名(参数类型 参数名){方法体 return返回值;} public int nums(String name){ //方法体 return num_a; } 3、C#: 访问修饰符+返回值类型+方法名(参数类型 参数名){方法体 return返回值;} public int nums(string name){ //方法体 return num_a; }
1、Python: 导入库名:import time 2、Java: 导入包名:import java.io.*; 3、C#: 导入命名空间:using System.Threading;
注意:元组一旦定义就不能修改
course=(‘Chinese’,‘Math’,‘English’,‘Computer’) print(course) print(course[0]) #索引从0开始,第一个元素 print(course[-1]) #倒数第一个元素 print(course[1:3]) #截取元素,索引从1至3,但不包括索引3的元素 print(course[1:]) #截取索引从1到最后 print(course[:1]) #截取索引从0至1 print(len(course)) #元组的长度 del course #删除元组