测试工程师之Python面试题(附答案)
1、请把字符串“abcde”里面的字符,逐个,打印出来
ss="abcdefgh"
for i in ss:
print(i)
2、对字符串“www.autotestplat.com",输出为“com.autotestplat.www"
ss = "www.autotestplat.com"
list_ss = list(ss.split('.'))
list_ss.reverse()
print(".".join(list_ss))
3、把一个列表里面的数字元素,去重,如 {1,1,2,2,3,3,4,4,5,5}
aa = [1,1,2,2,3,3,4,4,5,5,5]
bb = list(set(aa))
print(bb)
4、用递归实现数字的阶乘,N!,n=9时,s=9*8*7*6*5*4*3*2*1
def a(n):
if int(n)<= 1:
return 1
else:
return n*a(n-1)
print(a(9))
5、对字符串
{"a":"0","b":"1","d":"11","e":"22","f":"33"},
输出字典 {'a':'1','b':'1','d':'11','e':'22','f':'33'}
ss= '{"a":"0","b":"1","d":"11","e":"22","f":"33"}'
dict_ss = eval(ss)
print(dict_ss)
6、以下代码:
a="05550550"
print(a.index("x")
运行结果是:
ValueError: substring not found
7、以下几行字符串
fin one :13700010001 15 52A
fin two :13700020002 15 52B
fin three:13700030003 15 52C
依次代表 姓名 :手机号 楼栋号 房间号
请输出
姓名 :...,电话:...........,住址:......
姓名 :...,电话:...........,住址:......
姓名 :...,电话:...........,住址:......
str1 = 'fin one :13700010001 15 52A'
str2 = 'fin two :13700020002 15 52B '
str3 = 'fin three:13700030003 15 52C'
a1 = str1.split(':')
a11 = a1[1].split(' ')
a2 = str2.split(':')
a22 = a2[1].split(' ')
a3 = str3.split(':')
a33 = a3[1].split(' ')
print("姓名:"+a1[0]+",电话:"+a11[0]+",住址:"+a11[1]+" "+a11[2])
print("姓名:"+a2[0]+",电话:"+a22[0]+",住址:"+a22[1]+" "+a22[2])
print("姓名:"+a3[0]+",电话:"+a33[0]+",住址:"+a33[1]+" "+a33[2])
8、实现一个冒泡排序
data = [2,10,7,8,9,5,4,1]
def bubble_sort(arr):
for i in range(len(data)-1):
for j in range(len(data)-1-i):
if data[j]>data[j+1]:
data[j+1],data[j]=data[j],data[j+1]
return data
print(bubble_sort(data))