• Python 2.x和3.x不同点


    1.print和print()

    2.yield

    出现下面的错误
    Traceback (most recent call last):
    File “<pyshell#32>”, line 1, in <module>
    f.next()
    AttributeError: ‘generator’ object has no attribute ‘next’
    原因是在python 3.x中 generator(有yield关键字的函数则会被识别为generator函数)中的next变为__next__了,next是python 3.x以前版本中的方法

    3.unicode

    在Python3.x中, 没有预定义unicode类型了,内置字符串就是str, 但是str中的字符都是unicode编码的 

    4.cmp()

    在Python3.x中开始没这个函数了,官方文档是这么写的
    The cmp() function should be treated as gone, and the __cmp__() special method is no longer supported. Use __lt__() for sorting, __eq__() with __hash__(), and other rich comparisons as needed. (If you really need the cmp() functionality, you could use the expression (a > b) - (a < b) as the equivalent for cmp(a, b).)
    大意就是cmp()函数已经“离开”了,如果你真的需要cmp()函数,你可以用表达式(a > b) - (a < b)代替cmp(a,b)

  • 相关阅读:
    LINQ Practice
    windows下python环境安装
    kafka安装教程
    使用python连接mysql/oracle
    使用百度地图实现地图网格
    单链表反转java代码
    mysql的索引问题分析
    java中String字符串的==解析
    辗转相除法的原理
    myeclipse2014新建maven项目
  • 原文地址:https://www.cnblogs.com/edisonxiang/p/4613380.html
Copyright © 2020-2023  润新知