面试题

Posted lhybky

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了面试题相关的知识,希望对你有一定的参考价值。

1.Python里的reduce函数有什么用法
from functools import reduce
def fun(x,y):
    return 10*x+y

l=reduce(fun,(1,2,3,4))
print(type(l),l)

 

2.请写出一段Python代码实现删除一个list里面的重复元素,例如l=[1,2,3,3,4,4,5]
 

 

l=[1,2,3,3,4,4,5] d ={} 
 d=d.fromkeys(l)
print(list(d))

 

3.Python里面如何生成随机数?
import random
l = random.randint(198,200)

print(l)
l = random.randrange(100)
print(l)

 

4.简述列表,字符串,元组,字典之间异同。
有序性:前三者都是有序的,由于此性质决定了,可以用成员运算符 
in or not in,可以索引[],可以切片,拼接,len(),.count(),.index()
max(),min()
可变性:列表,字典都是可变的,都可以增删改查

 



以上是关于面试题的主要内容,如果未能解决你的问题,请参考以下文章