@: python_today
1. 将百分数字符串转换为浮点数的方法(x = ’20%’)
- eval(x.replace(‘%’, ‘/100.0’)
注意:eval()是求值函数 - float(x.strip(‘%’))/100
- float(x[:-1])/100
2. list的常见用法
- 改变list中某个item, 直接 list[3] = item, 就把原来的替换了
- 插入list.insert(position, item)在position位置插入item,原位置item后移
- list.append(list)
list1 = [4] list2 = [2, 3]
list1.append(list2)
list1 = [4, [2,3]] - list.extend(list)
list1 = [4] list2 = [2, 3]
list1.extend(list2)
list1 = [4, 2, 3] - 删除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)