代码示例库

搜索、筛选并收藏你需要的 Python 代码片段。

重置
#入门 #字符串 #数字 #列表 #列表 #循环 #切片 #if #列表 #字典 #字典 #while #while #函数 #函数 #类 #类 #文件 #异常 #测试 #测试 #Pygame #Pygame #matplotlib #随机漫步 #CSV #API #Django #Django #Django

for循环遍历

第4章 操作列表

演示for循环遍历列表与range。

magicians = ["alice", "david", "carolina"]
for magician in magicians:
    print(f"{magician.title()}, 该你表演了!")

for value in range(1, 6):
    print(value)

squares = [x**2 for x in range(1, 11)]
print(squares)
print(f"总和: {sum(squares)}")