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

python 数据类型

作者:半盏流年   发布日期:2026-03-28   浏览:99

# Python 数据类型示例

# 1. 整数 (int)
integer_example = 42
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, 4, 5)
print(f"元组装示例: {tuple_example}, 类型: {type(tuple_example)}")

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

# 8. 字典 (dict)
dict_example = {"name": "Alice", "age": 30}
print(f"字典示例: {dict_example}, 类型: {type(dict_example)}")

解释说明:

  • 整数 (int): 表示整数值,例如 42
  • 浮点数 (float): 表示带有小数点的数值,例如 3.14
  • 字符串 (str): 表示文本数据,用引号括起来,例如 "Hello, World!"
  • 布尔值 (bool): 表示真或假的值,例如 TrueFalse
  • 列表 (list): 是一个有序的可变集合,可以包含不同类型的元素,例如 [1, 2, 3, 4, 5]
  • 元组 (tuple): 是一个有序的不可变集合,可以包含不同类型的元素,例如 (1, 2, 3, 4, 5)
  • 集合 (set): 是一个无序且不重复的元素集合,例如 {1, 2, 3, 4, 5}
  • 字典 (dict): 是一个键值对的集合,用于存储映射关系,例如 {"name": "Alice", "age": 30}

上一篇:python 打包

下一篇:python try catch

大家都在看

python 二维码识别

python excel 库

python时间格式

pythoneval函数用法

列表切片操作python

python读取文件路径

staticmethod在python中有

python 保存json文件

python开发windows应用程序

python中len是什么意思

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

Laravel 中文站