在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),此代码将引发错误。 但是,如果您将该语法行更改为键入(x)。 该类型在django的runserver上不返回输出。
I am having a hard time of determining the type of my variable since I am used on python2 and have just migrated to python3
from django.http import HttpResponse def myview(request): x = "Name" print (x) print type(x) return HttpResponse("Example output")This code will throw an error because of print type(x). However if you changed that syntax line to type(x). The type does not return an output on the runserver of django.
最满意答案
在Python 3中print不再是一个声明,而是一个函数。 你需要用括号来称呼它:
print(type(x))print in Python 3 is no longer a statement, but a function. You need to call it using parentheses:
print(type(x))更多推荐
发布评论