開始使用免費開始

使用 os 模組

在影片中,你認識了不同的 Python 模組及其實務應用。os 模組可讓你與作業系統互動——瀏覽目錄、檢查環境設定、管理檔案。瞭解目前的工作目錄與環境變數,對於偵錯檔案存取問題非常重要。

本練習屬於課程

Intermediate Python for Developers

檢視課程

練習說明

  • 匯入 os 模組。
  • 取得目前的工作目錄。
  • 檢查環境變數。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import the os module
import ____

# Get the current working directory
print("Current working directory:", os.____())

# Check the environment variables
print("Environment variables:", os.____)
編輯並執行程式碼