Python 中的 type() 函数 是一个用于获取对象类型的内置函数。它将对象的类型作为 type 类型的返回值,可用于确定传递给函数作为参数的对象的类型。
参数值
| 参数 | 说明 |
|---|---|
| obj | 要返回其类型的对象。 |
返回值
type() 函数返回一个 type 对象,如果提供了参数,则返回一个新类型。
如何在 Python 中使用 type()
示例 1
type() 函数返回对象的类型。它对于检查 变量 或 Python 中的对象 的类型非常有用。
type(5) # Output:
type('hello') # Output:
type([1, 2, 3]) # Output: