Python习题1
1.請列舉 python2 與 python3 的區別,請將下面的 python2 代碼轉換成
python3。
class Point: def init(self, x, y): self.x = x self.y = y def
str(self): return ‘({}, {})’.format(self.x, self.y) points = [Point(9, 2), Point(1,5), Point(2, 7), Point(3, 8), Point(2, 5)]
sorted_points = sorted( points, lambda (x0, y0), (x1, y1): x0 - x1 if
x0 != x1 else y0 - y1, lambda point: (point.x, point.y))
#預期結果為(1, 5), (2, 5), (2, 7), (3, 8), (9, 2) print ', '.join(map(str, sorted_points)
Python2轉python3代碼實現:
class Point(): def init(self,x,y):
self._x = x
self._y = y def get_value(self):
return self._x,self._y
points = [Point(9,2),Point(1,5),Point(2,7),Point(3,8),Point(2,5)]
points.sort(key=lambda x:x.get_value()) points_value =
[str(p.get_value()) for p in points] print(",".join(points_value))
請用 python 寫一個正則表達式實現電話號碼的提取功能,下面是需要滿足條 件:
a. 匹配(123)-456-7890 和 123-456-7890 b. 不匹配(123-456-7890 和 123)-456-7890正則表達式提取電話號碼:
3.請用 python 寫一個正則表達式實現如下內容的匹配,并實現數據的結構化
b6b2af4a-02cb-4a45-819e-c35a74186608 300363 關于公司為全資子公司 Porton
USA,L.L.C.申請融資提供擔保的公告 2017-01-25
{
‘uuid’: ‘b6b2af4a-02cb-4a45-819e-c35a74186608’,
‘code’: ‘300363’,
‘title’: ‘關于公司為全資子公司 Porton USA,L.L.C.申請融資提供擔保的公告’,
‘date’: ‘2017-01-25’
}
4.描述 python 開發中,協程,線程和進程的區別,請將下面代碼改成可以在多
核 CPU 上并行執行的程序。
5 請列常用的 python library,并說明其作用基本使用示例
6.請解釋什么是 CORS 問題,在什么樣的情況下,會遇到這個問題,常用的 python 庫里面該怎么解決這個問題。
總結
- 上一篇: 浅谈tcp的三次握手和四次挥手的理解
- 下一篇: Python习题2