Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

python 变量类型

作者:洃铯哖輪   发布日期:2025-12-15   浏览:36

# Python 变量类型示例

# 1. 整数类型 (int)
integer_example = 10
print(f"整数类型: {integer_example}, 类型: {type(integer_example)}")

# 2. 浮点数类型 (float)
float_example = 3.14
print(f"浮点数类型: {float_example}, 类型: {type(float_example)}")

# 3. 字符串类型 (str)
string_example = "Hello, World!"
print(f"字符串类型: {string_example}, 类型: {type(string_example)}")

# 4. 布尔类型 (bool)
boolean_example = True
print(f"布尔类型: {boolean_example}, 类型: {type(boolean_example)}")

# 5. 列表类型 (list)
list_example = [1, 2, 3, 4, 5]
print(f"列表类型: {list_example}, 类型: {type(list_example)}")

# 6. 元组类型 (tuple)
tuple_example = (1, 2, 3)
print(f"元组类型: {tuple_example}, 类型: {type(tuple_example)}")

# 7. 字典类型 (dict)
dict_example = {"name": "Alice", "age": 25}
print(f"字典类型: {dict_example}, 类型: {type(dict_example)}")

# 8. 集合类型 (set)
set_example = {1, 2, 3, 4, 5}
print(f"集合类型: {set_example}, 类型: {type(set_example)}")

解释说明:

  • 整数类型 (int): 表示整数值,如 10
  • 浮点数类型 (float): 表示带小数点的数值,如 3.14
  • 字符串类型 (str): 表示文本数据,如 "Hello, World!"
  • 布尔类型 (bool): 表示真或假的值,如 TrueFalse
  • 列表类型 (list): 有序的可变序列,可以包含不同类型的元素,如 [1, 2, 3, 4, 5]
  • 元组类型 (tuple): 有序的不可变序列,如 (1, 2, 3)
  • 字典类型 (dict): 键值对的集合,如 {"name": "Alice", "age": 25}
  • 集合类型 (set): 无序且不重复的元素集合,如 {1, 2, 3, 4, 5}

每个变量类型都通过 type() 函数来显示其具体类型。

上一篇:python中len

下一篇:python 命令行

大家都在看

python时间格式

pythoneval函数用法

python读取文件路径

staticmethod在python中有

python开发windows应用程序

python中len是什么意思

python ord和chr

python中的yield

python自定义异常

python判断路径是否存在

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站