辨識好的註解
我們剛學過「好的」註解應該具備哪些特性。在這個練習中,你要運用這些觀念,找出一個符合註解最佳實務的函式。
本練習屬於課程
Python 的軟體工程原則
練習說明
print事先載入到你環境中的變數text。- 在
text上呼叫具有更實用註解的函式,並將結果print出來。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
import re
def extract_0(text):
# match and extract dollar amounts from the text
return re.findall(r'\$\d+\.\d\d', text)
def extract_1(text):
# return all matches to regex pattern
return re.findall(r'\$\d+\.\d\d', text)
# Print the text
____
# Print the results of the function with better commenting
print(____)