码迷,mamicode.com
首页 > 编程语言 > 详细

Python学习之路——基础04篇

时间:2017-06-01 10:23:13      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:div   and   log   bin   简单   数组操作   span   数组   学习   

  在python中,有很强大的for循环和很强大的数组操作,一些在其他语言中复杂的代码,在python中可以一行解决,下面是python中解决a,b数组所有偶数求和,存在c数组中的简单代码。

#!/usr/bin/env python3.6
#-*- coding: -utf8- -*-
x=[1,2,3,4]
y=[4,5,6,7]
c=[a + b for a in x for b in y if a%2 == 0 and b%2 ==0]
print(c)

 

Python学习之路——基础04篇

标签:div   and   log   bin   简单   数组操作   span   数组   学习   

原文地址:http://www.cnblogs.com/fyhsACr/p/6927116.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!