简体   繁体   中英

How to display the datatype of a variable in a python file

I know about the built-in function type()

It works fine in the interactive mode of python. But when you try and use it in a .py file, nothing gets displayed.

Which method should I use if I want to check the data type inside a python script/file?

It seems to me that the problem is not the type function, but rather how you are generating output. In interactive mode, stuff that you type on the console generates output, but when scripting it does not. You need to explicitly tell it to output:

print(type(x))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM