How to print data types in Python?

In Python, you can use the built-in function type() to print the data type.

For example, let’s say there is a variable x. You can use type(x) to print out the data type of x. Here is an example code:

x = 10
print(type(x))  # 输出:<class 'int'>

y = "hello"
print(type(y))  # 输出:<class 'str'>

z = [1, 2, 3]
print(type(z))  # 输出:<class 'list'>

Please note that the type() function returns a type object, which can be converted to a string format using the str() function for output.

bannerAds