python(二)

1.列举字符串,列表,元组,字典每个常用的五个方法
2.描述下列常见内置函数的作用可用代码说明map,zip,filter,sorted,reduce
3.列举你所知道的面相对象中的`__开头__`结尾的方法及作用,越多越好
4.写出form表单中所有的知识点
5.列举你所知道的所有css选择器

列举字符串,列表,元组,字典每个常用的五个方法

字符串

  • for
  • len
  • 索引
  • 切片
  • in
  • strip
  • split
  • startswith/endswith
  • lower/upper
  • join
  • replace
  • isdigit/isalpha
  • find/index/count
  • center/zfill/ljust/rjust

描述下列常见内置函数的作用可用代码说明map,zip,filter,sorted,reduce

res = map(lambda x: x + 1, [1,2,3])
print(list(res))   # [2, 3, 4]


res = filter(lambda x: x > 4, [2, 13, 4, 354, 6, 7])
print(list(res))   # [13, 354, 6, 7]

l1 = [1,2,3,4]
l2 = [11,22,33,44,55]
print(list(zip(l1, l2)))
# [(1, 11), (2, 22), (3, 33), (4, 44)]

lt = [23,4,25,2,32,51,0]
print(sorted(lt, reverse=True))   # [51, 32, 25, 23, 4, 2, 0]



from functools import reduce

l1 = [11,22,33,44,55]
res = reduce(lambda x, y: x + y, l1)
print(res)  # 165  reduce多个进来1个出去

posted @ 2019-11-17 20:14  SetCreed  阅读(100)  评论(0编辑  收藏  举报