测试你的Python 水平----6,,1、问:简述pyth


1、问:简述python中unicode和utf-8的关系?常用的函数有哪些?
答:unicode是一个字符编码集合,定义每个字符的唯一编码;utf-8则是unicode的一种实现,采用可变长编码来存储字符;常用的函数:
1) decode:实现从其他编码到unicode编码的转换
2) encode:实现从unicode到其他编码的转换

2、 代码段如下:
from functools import partial
def mul(x,base):return x*base
mul10=partial(mul,base=10)
mul100=partial(mul,100)
问:以下四个语句是否会出错?如果不出错,输出是什么?
1)print mul10(50)
2)print mul10(50,base=100)
3)print mul100(50)
4)print mul100(50,base=100)
答:
1) 500
2)5000
3)5000
4)报TypeError错误,传入多值

3、 问:简述python多重继承中方法解释顺序(Method Resolution Order)?
答:

1)经典类:深度优先,从左到右
2) 新式类:广度优先,从左到右

4、 问:列表:A=[1,2,2,2,2,7,6,3,2,6,8,3,4,4,4,3,2,9,124,456,124,96,78,2,3,4,6,6,8,5],请找出A中的重复的数字。
答:
A=A=[1,2,2,2,2,7,6,3,2,6,8,3,4,4,4,3,2,9,124,456,124,96,78,2,3,4,6,6,8,5]
setA=set(A)
for item in setA:
if A.count(item) >1:
print item,

5、写一段程序要求把一个文本中大于80个字符的文本行从最接近80个字符的单词断行,把剩余的文本插入到下一行,程序结束后,该文本中所有的行的字符数皆少于80个。


fpout=open(‘test.txt‘,‘r‘)
fpin=open(‘test1.txt‘,‘w‘)

for line in fpout:
if len(line)>80:
for i in range(80,0,-1):
#查找最接近80的字符单词
if line[i]==‘ ‘:
break
#截取
fpin.write(line[0:i]+‘\n‘)
fpin.write(line[i+1:])
else:
fpin.write(line)

fpout.close()
fpin.close()


测试你的Python 水平----6

相关内容

    暂无相关文章

评论关闭