What is the method for printing data types in Python?

In Python, you can use the type() function to print the data type. This function will return the type of the data. Here is an example:

x = 5
print(type(x))  # <class 'int'>

y = "Hello"
print(type(y))  # <class 'str'>

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

w = {"name": "John", "age": 30}
print(type(w))  # <class 'dict'>

In the example above, the type() function is used to print the data type of a variable, and the returned result is then printed out.

bannerAds