python2 和 python3 区别

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

猜你喜欢

转载自www.cnblogs.com/zhaoyingjie/p/9068632.html
今日推荐