11. Pathlib Module
These examples cover the basics and common use cases of the pathlib module, including creating paths, managing directories and files, and reading/writing file content.
from pathlib import Path
path = Path("/home/user/documents")
print(path) # Output: /home/user/documentsfrom pathlib import Path
path = Path("example.txt")
print(path.exists()) # Output: True or Falsefrom pathlib import Path
dir_path = Path("new_folder")
dir_path.mkdir(exist_ok=True)
print(f"Directory created: {dir_path}")Last updated