返回信息流今天被问到的。。
这是一条镜像帖。来源:北邮人论坛 / python / #7793同步于 2015/7/14
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖
有一种面试题,叫Python和JavaScript的区别
Footprints
2015/7/14镜像同步17 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
风格:Python遇到任何不正常的东西都会报错;JavaSript似乎很“容忍”,给你难以理解的行为。
看这里:
https://www.destroyallsoftware.com/talks/wat
V8 version 4.5.0 (candidate) [console: dumb]
d8> [] + []
""
d8> [] + {}
"[object Object]"
d8> {} + []
0
d8> {} + {}
NaN
d8> Array(14)
[, , , , , , , , , , , , , ]
d8> Array(14).join("foo")
"foofoofoofoofoofoofoofoofoofoofoofoofoo"
d8> Array(14).join("foo"+1)
"foo1foo1foo1foo1foo1foo1foo1foo1foo1foo1foo1foo1foo1"
d8> Array(14).join("foo"-1) + "Batman!"
"NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNBatman!"
Python 3.4.3 (default, Feb 25 2015, 21:28:45)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> [] + []
[]
>>> [] + {}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "dict") to list
>>> {} + []
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'dict' and 'list'
>>> {} + {}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'dict' and 'dict'
>>> [None]*14
[None, None, None, None, None, None, None, None, None, None, None, None, None, None]
>>> "foo".join([None]*14)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected str instance, NoneType found
>>> "foo"+1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Can't convert 'int' object to str implicitly
>>> "foo"-1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'str' and 'int'
此贴招来了暖神 我感到万分荣幸
【 在 nuanyangyang 的大作中提到: 】
: 风格:Python遇到任何不正常的东西都会报错;JavaSript似乎很“容忍”,给你难以理解的行为。
: 看这里:
: https://www.destroyallsoftware.com/talks/wat
: ...................
【 在 nuanyangyang 的大作中提到: 】
: 风格:Python遇到任何不正常的东西都会报错;JavaSript似乎很“容忍”,给你难以理解的行为。
: 看这里:
: https://www.destroyallsoftware.com/talks/wat
: ...................
JS不报错简直是天坑。。
毕竟 Python 是强类型
【 在 nuanyangyang 的大作中提到: 】
: 风格:Python遇到任何不正常的东西都会报错;JavaSript似乎很“容忍”,给你难以理解的行为。
: 看这里:
: https://www.destroyallsoftware.com/talks/wat
: ...................
Python怎么回会是强类型呢,变量定义也不需要必须指定类型啊
【 在 qxd12 的大作中提到: 】
: 毕竟 Python 是强类型
来自「北邮人论坛手机版」
比如上面暖神说的那几个 JS 跑得过而 Python 跑不过的代码就是例子阿。
参考:https://zh.wikipedia.org/wiki/Python#.E6.95.B0.E6.8D.AE.E7.B1.BB.E5.9E.8B.26.E5.8A.A8.E6.80.81.E7.B1.BB.E5.9E.8B
https://www.v2ex.com/t/61513
【 在 fanyuelin555 的大作中提到: 】
: Python怎么回会是强类型呢,变量定义也不需要必须指定类型啊
: 来自「北邮人论坛手机版」