pythonjava语法区别有哪些
1、变量
java中定义变量,inta=0;而python中为a=0;由此可见java要事先申明数据类型,python中无需事先申明数据类型,拿来就可以用,Python的语法要比Java更灵活。
2、分号
java的编程语句必须以分号结尾,而python中无需分号结尾。
3、数组
java中数组只能存一种数据类型,而python中可以存多种数据类型。
4、数据类型
Python有五个标准的数据类型:
·Numbers(数字)
·String(字符串)
·List(列表)
·Tuple(元组)
·Dictionary(字典)
上面跟java不同的是多了元组,数据字典,少了set,map数据类型
其中元组不能二次赋值,相当于只读列表。
字典是无序的对象集合,是通过键值对来存取
Python支持四种不同的数字类型:
·int(有符号整型)
·long(长整型[也可以代表八进制和十六进制])
·float(浮点型)
·complex(复数)
java支持八种基本数据类型:byte、short、int、long、float、double、char、boolean
5、字符串
java中用方法contains来字符串中是否包含元素
python中用in来判断字符串中是否包含元素
python中的址is比较的是地,==比较的是值,根据java的相反
6、if语法
python中的语法为if---elif
java中的语法为if--ifelse--
7、导入语句
from…import*语句
把一个模块的所有内容全都导入到当前的命名空间也是可行的,只需使用如下声明:
根据java的不同是,java是在类的后面加*,比如importorg.apache.*
8、构造函数
self代表类的实例,self在定义类的方法时是必须有的,虽然在调用时不必传入相应的参数。
java构造函数是类名的名称,而python的构造函数的名称是_init_
在类的内部,使用def关键字可以为类定义一个方法,与一般函数定义不同,类方法必须包含参数self,且为第一个参数
9、运算符
Python中没有++或--自运算符
以上内容为大家介绍了python培训之java语法区别有哪些,希望对大家有所帮助,如果想要了解更多Python相关知识,请关注IT培训机构:千锋教育。

相关推荐HOT
更多>>
python函数标注是什么
python函数标注是什么在参数的使用方法中,还有一种解包的情况是需要我们掌握的。比如,将列表或者字典的值转换为函数的参数,就需要用到参数解...详情>>
2023-11-14 14:13:35
python正负索引的使用
python正负索引的使用本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。1、说明使用正索引(从左至右)、负索引(从右至左)访问元素,时...详情>>
2023-11-14 13:45:04
python垃圾回收的机制过程
python垃圾回收的机制过程本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。1、步骤(1)收集所有容器对象(list,dict,tuple,customClas...详情>>
2023-11-14 13:05:15
pythontry语句的执行原理
pythontry语句的执行原理1、原理分析(1)执行try子句(try和except关键字之间的多行语句)。(2)如果没有异常发生,则跳过except子句并完成try语句...详情>>
2023-11-14 09:37:35热门推荐
技术干货






