python小杂记

1、

a = b    # 复制地址
a = b[ : ]    #复制值

2、使用 sys.stdin.readlines()时,停止输入 windowns下使用 ctrl+z , Linux下使用 ctrl+d
以此种方式返回值包含' ',input()方式不会有,但一个Enter即止
3、

while True:
    a,b = map(int, input().strip().split())
except EOFError:
    break

4、大规模查找时使用dict或set,因为它们存储时用的是红黑树结构,查找起来快
大规模插入时用list,因为它是顺序插入,快,而dict是连续插入的,还要不断hash计算key对应的内存位置

5、字符串

str.count('目标', '起始位置', '结束位置')
str.endswitch('xxx', 'xxx', ...)    # 判断是否以n个xxx中的一个结束
str.index('xxx')    # 与find不同的是没有找到会报错
str.find('xxx')    # 没找到返回-1,找到返回位置
str.lstrip([xxx])
str.rstrip([xxx])

6、列表
list.remove('xxx') # 等同于del list[int]
len / max / min /list(seq)
list.append(xxx)/count()/index(xxx)/insert(位置,值)/remove(xxx)/reverse()/sort()

原文地址:https://www.cnblogs.com/wolun666/p/14662857.html