python是弱类型语言吗


本文摘自php中文网,作者anonymity,侵删。

python是弱类型语言吗?不是的,Python属于强类型的动态脚本语言

强类型:不予许不同类型相加

动态:不使用显示数据声明类型,且确定一个变量的类型是第一次给他赋值的时候

脚本语言:一般也是解释性语言,运行代码只需要一个解释器,不需要编译

这里对强类型和弱类型进行对比:

python代码:

1

2

3

4

5

6

7

8

9

10

11

12

>>> 3+6

9

>>> "3"+6

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

TypeError: Can't convert 'int' object to str implicitly

>>> "3"+"6"

'36'

>>> "6"-"3"

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

TypeError: unsupported operand type(s) for -: 'str' and 'str'

javascript代码:

1

2

3

4

5

6

7

8

3+6

9

"3"+6

"36"

"3"+"6"

"36"

"6"-"3"

3

以上就是python是弱类型语言吗的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

Python里range是什么

Python是面向对象还是面向过程?

Python中使用三种方法判断文件或文件夹是否存在的实例分享

Python怎么运行脚本?

Python os.chown() 方法是什么?它有什么样的作用?

mac怎么使用Python

Python序列类型包括哪三种

Python能做什么?是什么?

visual studio 创建 Python flaskweb 项目运行时报“no module named flask”错

详解Python 2.6 升级至 Python 2.7 的实践心得

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...