深度阅读

How to check the data type of a variable or object in Python

作者
作者
2023年08月22日
更新时间
5.22 分钟
阅读时间
0
阅读量

In Python, you can use the type() function to check the data type of a variable or object. Here are some examples:

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

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

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

The type() function returns a type object that represents the data type of the variable or object. You can use this function to check the data type of any variable in your Python code.

I hope this helps! Let me know if you have any further questions.

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。