• 技术文章 >后端开发 >Python教程

    python是弱类型语言吗

    anonymityanonymity2019-06-15 09:56:45原创2788
    python是弱类型语言吗?不是的,Python属于强类型的动态脚本语言

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

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

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

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

    python代码:

    >>> 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代码:

    3+6
    9
    "3"+6
    "36"
    "3"+"6"
    "36"
    "6"-"3"
    3

    以上就是python是弱类型语言吗的详细内容,更多请关注php中文网其它相关文章!

    声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
    专题推荐:Python
    上一篇:python是强类型语言吗 下一篇:python软件版本的下载方式
    大前端线上培训班

    相关文章推荐

    • python中list的方法有什么• tkinter是python自带的吗• python爬虫用的哪些库• 现在学python该学python2还是python3?

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网