To create a new folder in Python, use the os
or pathlib
modules:
Using os
:
Using pathlib
:
Key Points:
- Replace
"new_folder"
with your desired folder name or path. exist_ok=True
avoids errors if the folder already exists.- Use
parents=True
to create intermediate directories if needed.