.py檔

.py檔案是Python 文件的類型,用來儲存Python程式。
當你在寫Python程式時,不一定要總是在互動模式中撰寫。
你可以在純文字文件中寫下你的Python程式。
例如以下文件 restring.py

def replace(string,target, rechar):
  temp = ""
  for i in string:
    if i is target:
      temp += rechar
    else:
      temp += i
  return temp

之後就可以從其他文件或著是互動模式中引入這份程式碼並使用
>>> import restring
>>> restring.replace("abcdabcdabcd","c","/")
'ab/dab/dab/d'