• Python 内部函数


    li = ['alex','eric','Roman']
    for i in enumerate(li,10):
    print (i)

    结果:

       (10, 'alex')
      (11, 'eric')
      (12, 'Roman')

     结论: enumerate方便给元素添加一个自增的序号

    print (ord('c'))
    print (chr(99))
    结果:

      99
      c

     结论:ord可以将字符转为ascii码,chr可以将ascii转为字符串

    a1 = "[[1,2], [3,4], [5,6], [7,8], [9,0]]"
    b1 = eval(a1)
    print (b1)
    print (type(b1))
    结果:

      [[1, 2], [3, 4], [5, 6], [7, 8], [9, 0]]
      <class 'list'>

     结论:字符串转换为列表


    a2 = "([1,2], [3,4], [5,6], [7,8], [9,0])"
    b2 = eval(a2)
    print (b2)
    print (type(b2))
    结果:

      ([1, 2], [3, 4], [5, 6], [7, 8], [9, 0])
      <class 'tuple'>

     结论:字符串转换为元祖


    a3 = "{1:'a',2:'b',3:'c'}"
    b3 = eval(a3)
    print (a3)
    print (type(b3))
    结果:

      {1:'a',2:'b',3:'c'}
      <class 'dict'>

     结论:字符串转化为字典

    li = [11,22,33,44]
    # new_li = list(map(lambda x:x+100,li))
    # print(type(new_li))
    # print (new_li)

    def func(x):
    x = x+100
    return x
    new_li = list(map(func,li))
    print (new_li)
    结果:[111, 122, 133, 144]
    结论:map函数将输入进行处理到输出,一对一的操作,map第一个参数为函数

    li = [11,22,33,44]
    def func(x):
    if x>22:
    return True
    else:
    return False
    f_li = list(filter(func,li))
    print (f_li
    结果:[33, 44]
    结论:通过filter函数可以通过函数来进行过滤操作


  • 相关阅读:
    CSS揭秘三(形状)
    CSS揭秘(二背景与边框)
    js数组去重
    Iterator
    ES6数据结构set
    JS浏览器对象(BOM)
    JS 数据类型转换
    js的cookie,localStorage,sessionStorage
    (html+css)云道首页
    蓝桥杯-基础练习 01字串-C语言-5层循环法
  • 原文地址:https://www.cnblogs.com/python-study/p/5451037.html
Copyright © 2020-2023  润新知