在django 1.8上的python3.5中打印变量类型(Print type of variable in python3.5 on django 1.8)

编程入门 行业动态 更新时间:2024-10-17 13:34:27
在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))

更多推荐

本文发布于:2023-08-04 13:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1416013.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   类型   django   type   Print

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!