本文摘自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实现输出带颜色的字符串案例分析
Python基础汇总
认识Python对象自省机制
Python中tornado的同步与异步i/o的介绍(附示例)
Python使用迭代器捕获generator返回值的方法
Python线程下条件变量的用法
Python如何遍历列表所有元素?
Python可以用来炒股吗
Python读写文件的代码示例
Python使用协程与并发有什么用?
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python是弱类型语言吗