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

Print type of variable in python3.5 on django 1.8

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

from django.http import HttpResponse

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

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

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

print(type(x))