在django 1.8上的python3.5中打印变量的类型

问题描述 投票:9回答:1

由于我在python2上使用并且刚刚迁移到python3,因此我很难确定变量的类型

from django.http import HttpResponse

def myview(request):
    x = "Name"
    print (x)
    print type(x)
    return HttpResponse("Example output")

由于打印类型(x),此代码将引发错误。但是,如果您将该语法行更改为type(x)。该类型不会在django的运行服务器上返回输出。

django python-3.5
1个回答
25
投票

print在Python 3中不再是一个语句,而是一个函数。您需要使用括号来调用它:


0
投票

好,但是如何以与print(type(x))相同的打印方式打印文本>

例如x = 5(int)

© www.soinside.com 2019 - 2024. All rights reserved.