# 示例代码:使用 type 函数来获取变量的类型
# 定义一个整数变量
x = 10
print(f"变量 x 的类型是: {type(x)}") # 输出: <class 'int'>
# 定义一个字符串变量
y = "Hello, World!"
print(f"变量 y 的类型是: {type(y)}") # 输出: <class 'str'>
# 定义一个列表变量
z = [1, 2, 3, 4, 5]
print(f"变量 z 的类型是: {type(z)}") # 输出: <class 'list'>
# 使用 type 创建自定义类
class MyClass:
pass
# 创建类的实例
my_instance = MyClass()
print(f"变量 my_instance 的类型是: {type(my_instance)}") # 输出: <class '__main__.MyClass'>
type() 函数用于返回对象的类型。type() 返回相应的内置类型。type() 返回类的名称,并且会显示类所在的模块(例如 __main__ 表示当前模块)。上一篇:python查找字符串
下一篇:python hist
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站