循环:操作列表
发布时间:2020-12-20 10:13:11 所属栏目:Python 来源:网络整理
导读:遍历列表 bis= ["sss","ass222","kjjga","dksjkgj"]for xx in bis : print(xx)sssass222kjjgadksjkgj 循环临时存储建议: for cat in cats:for dog in dogs:for item in list_of_items: 循环中执行更多操作: bis= ["sss","dksjkgj"]for xx in bis : print(x
遍历列表bis= ["sss","ass222","kjjga","dksjkgj"] for xx in bis : print(xx) sss ass222 kjjga dksjkgj 循环临时存储建议: for cat in cats: for dog in dogs: for item in list_of_items: 循环中执行更多操作: bis= ["sss","dksjkgj"] for xx in bis : print(xx + " 你好" "n") print("loop is end ") sss 你好 ass222 你好 kjjga 你好 dksjkgj 你好 loop is end 避免缩进错误Python根据缩进来判断代码行与前一个代码行的关系 创建数值列表列表非常适合用于存储数字集合 for xx in range(1,5): print(xx) 1 2 3 4 使用 range()创建数字列表 xxx = list(range(1,5)) print(xxx) for x in xxx: print(x) for value in range(1,11): xx = value ** 2 print(xx) 对数字列表执行简单的统计计算>>> digits = [1,2,3,4,5,6,7,8,9,0] >>> min(digits) 0 >>> max(digits) 9 >>> sum(digits) 45 列表解析squares = [value**2 for value in range(1,11)] print(squares) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |