What is the Python mkdir method?
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])
pathis the path where you want to complete the new directory.modeis the mode of the directory to be given. The default mode is .
In some systems, the mode parameter is ignored, which sets the current umask value.
Here is the complete implementation using default mode.
# import libraryimport os# this is the directory that will be createdpath = "/home/User/Downloads/myfolder"#use os.mkdir() to create the directoryos.mkdir(path)
The official documentation can be found here.
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved