How can we determine the type of a variable in Python?

In Python, you can use the type() function to check the type of a variable. For example:

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

y = 3.14
print(type(y))  # <class 'float'>

z = "Hello, world!"
print(type(z))  # <class 'str'>

In the above code, the types of the integer variable x, the float variable y, and the string variable z are printed using the type() function.

bannerAds