PPZ

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

2024年6月4日

摘要: enumerate() 函数是 Python 中常用的内置函数之一,用于同时遍历集合对象(如列表、元组、字符串等)的索引和元素。 用法: enumerate() 函数接受一个可迭代对象作为参数,并返回一个生成器对象,每次迭代生成器时,都会返回一个由索引和对应元素值组成的元组。 语法: enumera 阅读全文
posted @ 2024-06-04 20:48 犬卧 阅读(21) 评论(0) 推荐(0) 编辑

摘要: 1. 创建字符串 使用引号创建字符串 # 单引号 str1 = 'Hello, World!' # 双引号 str2 = "Hello, World!" # 三引号(可用于创建多行字符串) str3 = '''Hello, World!''' str4 = """Hello, World!""" 2 阅读全文
posted @ 2024-06-04 20:15 犬卧 阅读(4) 评论(0) 推荐(0) 编辑

摘要: 1. 创建字典 使用大括号 {} 创建空字典 empty_dict = {} print(empty_dict) # 输出: {} 使用 dict 函数创建字典 # 通过键值对创建字典 person = dict(name="Alice", age=30, city="New York") prin 阅读全文
posted @ 2024-06-04 09:46 犬卧 阅读(172) 评论(0) 推荐(0) 编辑

摘要: 1. 创建列表 使用 list 函数 创建空列表: empty_list = list() print(empty_list) # 输出: [] 从字符串创建列表: string = "hello" list_from_string = list(string) print(list_from_st 阅读全文
posted @ 2024-06-04 09:31 犬卧 阅读(24) 评论(0) 推荐(0) 编辑