Python容器 之 列表--下标和切片

  • 列表的切片 得到是 新的列表
  • 字符串的切片 得到是新的字符串
  • 如果下标 不存在报错
python 复制代码
list1 = [1, 3.14, "hello", False]
print(list1)

# 获取 列表中 第一个数据
print(list1[0])  # 1

# 获取列表中的最后一个数据
print(list1[-1])  # [False]

# 获取中间两个数 即 3.14和"hello" (即下标为1和2的数据)
print(list1[1:3:1])  # [3.14, 'hello']
print(list1[1:3:])  # [3.14, 'hello']

未完待续。。。

相关推荐
黄忠16 小时前
大模型之LangGraph技术体系
python·llm
hboot1 天前
AI工程师第二课 - 数据处理
人工智能·python·数据分析
用户8356290780511 天前
使用 Python 自动化 PowerPoint 形状布局与格式设置
后端·python
用户8356290780511 天前
用 Python 自动化 PowerPoint 演讲者备注添加
后端·python
黄忠2 天前
01-系统架构设计-LangGraph状态机与多源异构RAG
python
zzzzzz3102 天前
假如我是掘金管理员,我先给评论区装个'代码审查'系统
python·程序员·机器人
砍材农夫2 天前
python环境|conda安装和使用(2)
后端·python
程序员龙叔2 天前
编写高质量 Skill 系列 -- 如何设计需求分析与用例生成的 SKILL
自动化测试·软件测试·python·软件测试工程师·接口测试·性能测试·skill·ai测试
用户8356290780512 天前
使用 Python 操作 Word 内容控件
后端·python