日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python习题1

發布時間:2024/4/11 python 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 上并行執行的程序。

    import os import sys def dump_file(input_dir): if not os.path.exists(input_dir): print('dir {} not exists'.format(input_dir)) returnpath_list = [os.path.join(input_dir, f).strip('\n') for f in os.listdir(input_dir)]file_path_list = filter(lambda file_path: os.path.isfile(file_path), path_list)for file_path in file_path_list:print('{}:{} size:{}'.format(os.getpid(), file_path, os.path.getsize(file_path))) if __name__ == '__main__':if len(sys.argv) > 1:dump_file(sys.argv[1])else: dump_file(os.getcwd())

    5 請列常用的 python library,并說明其作用基本使用示例

    6.請解釋什么是 CORS 問題,在什么樣的情況下,會遇到這個問題,常用的 python 庫里面該怎么解決這個問題。

    總結

    以上是生活随笔為你收集整理的Python习题1的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。