What is the Python mkdir method?

svg viewer

Os.mkdir() method is used in python to try to create a path with a numeric mode.

Note: The method gives FileExistsError if the path already exists.

Here is the syntax for the mkdir method:

os.mkdir(path[,mode])

  • path is the path where you want to complete the new directory.
  • mode is the mode of the directory to be given. The default mode is 0777(octal)0777 (octal).

In some systems, the mode parameter is ignored, which​ sets the current umask value.

Here is the complete implementation using default mode.

# import library
import os
# this is the directory that will be created
path = "/home/User/Downloads/myfolder"
#use os.mkdir() to create the directory
os.mkdir(path)

The official documentation can be found here.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved