From 27f8fd6f66851b968f2c5904e9f515749d8b3ce5 Mon Sep 17 00:00:00 2001 From: sheeran <951202102@qq.com> Date: Mon, 14 Oct 2019 11:35:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python-interview-2019-3.md | 67 ++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/python-interview-2019-3.md b/python-interview-2019-3.md index 66cf49b..feb6ca3 100644 --- a/python-interview-2019-3.md +++ b/python-interview-2019-3.md @@ -2,9 +2,9 @@ > **答题要求**:将该项目从[地址1]()或[地址2]()**fork**到自己的[GitHub]()或[Gitee](https://gitee.com)仓库并在线填写答案,完成后以发送合并请求(**Pull Request**)的方式提交自己的工作成果,时间120分钟。 -#### 答题人: +#### 答题人:张志强 -#### 题目: +#### 题目:面试题 1. 下面的Python代码会输出什么。 @@ -14,7 +14,9 @@ print(len({x for x in 'hello world' if x not in 'abcdefg'})) ``` - 答案: + 答案:[(a, 1), (b, 2), (c, 3), (d, 4)] + {1: 'item1', 3: 'item9'} + 6 ``` @@ -32,7 +34,7 @@ 答案: ``` - + 13 ``` 3. 对于第2题的代码,如果要实现相同的功能,用生成式应该怎么写? @@ -48,6 +50,7 @@ 答案: ```Python + {x: y for x, y in ('k1:v1|k2:v2|k3:v3'.split('|').split(':'))} ``` @@ -56,6 +59,18 @@ 答案: ```Python + def change_str(func): + def wrapper(*args, **kwargs): + result = func(*args, **kwargs) + new_str = '' + if isinstance(result, str): + for item in result.split(' '): + for i in item: + change_up = i.upper() + item.replace(i, change_up) + break + new_str += item + return wrapper ``` @@ -78,6 +93,9 @@ 答案: ```Python + sorted(prices.items, key=lambda x: x[1])[-1][0] + + {item[0]: item[1] for item in sorted(prices.items, key=lambda x: x[1]) if item[1] > 100} ``` @@ -86,6 +104,12 @@ 答案: ```Python + def del_cover(arr): + new_arr = [] + for item in arr: + if item not in new_arr: + new_arr.append(item) + return new_arr ``` @@ -94,7 +118,19 @@ 答案: ```Python - + from collections import Counter + + + def find_num(arr): + arr_len = len(arr) + new_arr = [] + nums = Counter(arr).most_common() + for item in nums: + if item[1] >= (arr_len / 2): + new_arr.append(item[0]) + return new_arr + + ``` 9. MySQL关系型数据库中有三张表分别表示用户、房源和租房记录,表结构如下所示。 @@ -146,7 +182,22 @@ 答案: ```SQL - + select username + from tb_user + where userid in + (select userid + from tb_record + where houseid=1055); + + select username + from tb_user + where userid in + (select userid + from tb_record + where count(houseid) >= 3) + and usertel=True; + + ``` 10. 请阐述访问一个用Django或Flask开发的Web应用,从用户在浏览器中输入网址回车到浏览器收到Web页面的整个过程中,到底发生了哪些事情,越详细越好。 @@ -154,7 +205,9 @@ 答案: ``` - + 当用户在浏览器中输入网址按下回车,此时前端会发送一个request请求到后端,后端收到请求地址,调用视图views的对应函数, + 根据请求的类别,如是否是GET、POST、PUT等请求方式,进行相应的对数据库的增删查改操作,再将前端所需数据以json的格式 + 返回至templates模版,进行渲染,再到前端收到wen页面。 ``` 11. 请阐述HTTPS的工作原理以及TCP是如何保证端到端可靠传输的。 -- Gitee