前言
终于复习完了基础理论,现在进入python阶段。其实python如果你已经学习过了,那么此处复习的就应该是那些经常忘记,比较难写的函数库名和面试题等。
注意,一旦你简历中写了精通python,那么面试官不可能问你简单的常见的,比如列表的增删改查这种。问,就一定问一些比较偏门冷门的,所以这里进行列举:
常见易忘题:
1打印文件的相对路径/绝对路径/文件名等
print __file__ print os.path.abspath(__file__) print os.path.dirname(os.path.abspath(__fiel__))
2安全版的eval求值函数
ast.literal_eval
3获取列表中所有元素出现次数
collections.Counter(nums)
4列表获取所有子列表(按数量分组)
from itertools import combinations L = combinations(list,nums)
5列表/字母内各种排列组合
L = itertools.permutations(A)
6ascii对应
用chr()来变成字符 65-91 : 大写字母 97-123 : 小写字母 48-58: 数字
7输出固定常用字符串-string
import string string.digits : 0-9字符串 string.ascii_letters : 大小写字母 string.ascii_lowercase : 小写字母 string.ascii_uppercase : 大写字母
8各进制转十进制
int(x,2) int(x,8) int(x,16)
9各进制转二进制
必须先转成十进制
bin(int(x,8)) bin(int(x,10)) bin(int(x,16))
10各进制转八进制
必须先转成十进制
oct(int(x,2)) oct(int(x,10)) oct(int(x,16))
11各进制转十六进制
必须先转成十进制
hex(int(x,2)) hex(int(x,8)) hex(int(x,10))