首页 > 编程语言 > 详细

python2 和 python3 区别

时间:2018-05-21 19:02:52      阅读:148      评论:0      收藏:0      [点我收藏+]

python2

python 2 必须加object加入后是新式类
python 2 不加object是经典类
class HTTP(object):
    # 经典类和新式类
    @staticmethod
    def get(url,return_json = True):
        r = requests.get(url)
        #restful
        #json

        if r.status_code != 200:
            return {} if return_json else ‘‘
        return r.json() if return_json else r.text


Python3 无需增加object就是新式类
class HTTP():
    # 经典类和新式类
    @staticmethod
    def get(url,return_json = True):
        r = requests.get(url)
        #restful
        #json

        if r.status_code != 200:
            return {} if return_json else ‘‘
        return r.json() if return_json else r.text

 

python2 和 python3 区别

原文:https://www.cnblogs.com/zhaoyingjie/p/9068632.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!