# 10+5的结果放到列表中print([10 + 5])# 10+5这个表达式计算10次print([10 + 5 for i in range(10)])# 10+i 的i来自于循环print([10 + i for i in range(10)])print([10 + i for i in range(1,11)])# 通过if过滤,满足if条件的才参与10+i的运算print([10 + i for i in range(1, 11) if i % 2 == 1])print([10 + i for i in range(1, 11) if i % 2 == 0 ])# 生成ip地址列表print(['192.168.1.%s' % i for i in range(1, 255)])
结果输出: