一轮面试题:
python相关
1,*args和**kwarg有什么用?
如果我们不确定要往函数中传入多少个参数,或者我们想往函数中以列表和元组的形式传参数时,那就使要用*args;
如果我们不知道要往函数中传入多少个关键词参数,或者想传入字典的值作为关键词参数时,那就要使用**kwargs;
当我们混合使用这三个参数时,必须遵循arg,*args,**kwargs这样的顺序,否则程序会报错
2,[1,2,3]+[4,5,6]
[1,2,3,4,5,6]
3,给你一个字符串 abcde,倒序输出 edcba,怎么写
a=’abcde’ b=a[::-1]
4,取出100以内不能被3整除的数
a = [i for i in range(100)]
b = a[:]
for n in a:
if n % 3 == 0:
b.remove(n)
print(b)
5,取出邮箱地址@以前的部分,然后把数字删掉
def remove(a):
b = []
for i in a:
if i not in "0123456789":
b.append(i)
return ("".join(b))
print(remove('asdf234dsfg2345dfgf@#!#@'))
6,装饰器有什么作用?能写一个吗?
7,xxa!!@abc989HHaabbcc@abcccbac
把里面b左边紧紧相邻的a删掉,输出结果
m = 'xxa!!@abc989HHaabbcc@abcccbac'
while 'ab' in m:
m = m.replace('ab', 'b')
if 'ab' not in m:
break
print(m)
8,给你一个任意数,判断该数是不是7的N次方
比如 2348923499
def isPowerOfThree(n):
if n == 1:
return True
if (n >1 and n <= 6) or n==0:
return False
while n != 1:
if n % 7 == 0:
n = n / 7
else:
return False
return True
print(isPowerOfThree(2))
9,一个五位数,ABCDE,乘以9,等于EDCBA
求这个五位数
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
for e in range(10):
if (((10000 * a + 1000 * b + 100 * c + 10 * d + e) * 9) == (
10000 * e + 1000 * d + 100 * c + 10 * b + a)) and (a * e != 0):
print(a, b, c, d, e)
linux相关
1,linux的host文件路径在哪里,有什么作用?
Linux系统位置
/etc/hosts
作用:
hosts就相当于本地的一个dns缓存
可以用来屏蔽任何网站
ip地址+空格+域名+#解析+回车”
2,echo ‘abcde’ >> tmp.txt 和 echo ‘abcde’ >tmp.txt 是做什么的?
文件不存在时,两个命令都会新建文件
echo ‘abcde’ >> tmp.txt 在文件中追加内容
echo ‘abcde’ >tmp.txt 清空原来的内容,填入新的内容
3,linux系统非常卡顿,如何定位分析? free、top、ps -aux ?
查看系统性能情况
free top ps df du
du -sh 目录 查看指定目录的使用情况
4,crontab 命令的用途是? crontab -l?
crontab 和定时任务相关的命令
crontab -l 查看当前的定时任务设置
5,如何查看硬盘用量?如何查看某个文件夹的容量?
df -h
du -sh 目录 查看指定目录的使用情况
6,在/tmp目录下,寻找一个叫abc.log的文件,用什么命令?
find /tmp -name abc.log
7,vim和vi,按什么键可以回到文本的第一行和最后一行
vi 编辑器中跳到文件的第一行:键盘按下 小写 gg
vi 编辑器跳到文件最后一行:键盘按下大写 G