摘要:
``` sum_value = 0 for i in range(1,101): if i % 2 == 1: continue sum_value += i print(sum_value) print(sum([x for x in range(1,101) if x % 2 == 0])) 结 阅读全文
摘要:
``` print(sum(range(1,101))) print(sum([x for x in range(1,101)])) sum_value = 0 for i in range(1,101): sum_value += i print(sum_value) 结果: 5050 5050 阅读全文
摘要:
> 要求打印字典中值小于1的key和value ``` d = {"a": 1, "b":2, "c":3} d = {key: value for key,value in d.items() if value value是可以直接计算的 ``` d = {"a": 1, "b":2, "c":3 阅读全文
摘要:
第一种写法:通过set特性去重,但是不保证顺序,无序的 ``` a = ["1", 1, "1", 2] a = list(set(a)) print(a) 结果: [1, 2, '1'] ``` 第二种写法:可以保证和原来顺序一样 ``` a = ["1", 1, "1", 2] b = [] f 阅读全文
摘要:
``` int_list = range(1, 55, 2) print(list(int_list)) 结果: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 4 阅读全文