YouTip LogoYouTip

Python3 Os Mkdir

# Python3.x Python3 os.mkdir() Method [![Image 3: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#) * * * ### Overview The `os.mkdir()` method is used to create a directory with a numeric permission mode. The default mode is `0777` (octal). If the directory has multiple levels, only the last level is created. If the parent directory of the last level does not exist, an `OSError` will be raised. ### Syntax The syntax for the `mkdir()` method is as follows: os.mkdir(path[, mode]) ### Parameters * **path** -- The directory to be created. It can be a relative or absolute path. * **mode** -- The numeric permission mode to set for the directory. ### Return Value This method does not return a value. ### Example The following example demonstrates the use of the `mkdir()` method: ## Example #!/usr/bin/python # -*- coding: UTF-8 -*- import os,sys # Directory to be created path ="/tmp/home/monthly/daily/hourly" os.mkdir( path,0755) print("Directory created") The output of executing the above program is: Directory created [![Image 4: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#)
← Python3 Os MkdirPython3 Os Makedirs β†’