python_today 11_8

作者: 小黑天天快乐 | 来源:发表于2016-11-08 22:21 被阅读14次

@: python_today

1. 将百分数字符串转换为浮点数的方法(x = ’20%’)

  1. eval(x.replace(‘%’, ‘/100.0’)
    注意:eval()是求值函数
  2. float(x.strip(‘%’))/100
  3. float(x[:-1])/100

2. list的常见用法

  1. 改变list中某个item, 直接 list[3] = item, 就把原来的替换了
  2. 插入list.insert(position, item)在position位置插入item,原位置item后移
  3. list.append(list)
    list1 = [4] list2 = [2, 3]
    list1.append(list2)
    list1 = [4, [2,3]]
  4. list.extend(list)
    list1 = [4] list2 = [2, 3]
    list1.extend(list2)
    list1 = [4, 2, 3]
  5. 删除list元素的几种方法:
    li = [ 2, 3, 4, 5, 6, 7, 8, 9]
  • li[3:] = []
  • del(li[3:])
  • pop(-1)
    delete the item and return it, could be of special use
  • remove(9)

相关文章

  • python_today 11_8

    @: python_today 1. 将百分数字符串转换为浮点数的方法(x = ’20%’) eval(x.rep...

  • LPTHW NOTES 4

    @: python_today 11-4 1. str.split([sep[, maxsplit]]) 返回一个...

  • python_today 11\22

    在python中实现平抛运动的演示 代码如下 # coding: utf-8 from Tkinter impor...

网友评论

    本文标题:python_today 11_8

    本文链接:https://www.haomeiwen.com/subject/aalzuttx.html