# 示例代码:打印变量的类型
# 定义不同类型的变量
integer_var = 42
float_var = 3.14
string_var = "Hello, World!"
list_var = [1, 2, 3]
dict_var = {"key": "value"}
tuple_var = (1, 2, 3)
set_var = {1, 2, 3}
# 打印每个变量的类型
print(f"Integer variable type: {type(integer_var)}") # 输出: <class 'int'>
print(f"Float variable type: {type(float_var)}") # 输出: <class 'float'>
print(f"String variable type: {type(string_var)}") # 输出: <class 'str'>
print(f"List variable type: {type(list_var)}") # 输出: <class 'list'>
print(f"Dictionary variable type: {type(dict_var)}") # 输出: <class 'dict'>
print(f"Tuple variable type: {type(tuple_var)}") # 输出: <class 'tuple'>
print(f"Set variable type: {type(set_var)}") # 输出: <class 'set'>
type()
函数用于获取变量的数据类型。print()
函数和格式化字符串输出每个变量的类型。上一篇:python空格字符串怎么打
下一篇:python求余数的方法
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站