Easy Tutorial
❮ Ref Random Randint Python String Isdigit ❯

Python3 os.mkdir() Method

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 directories of the last level do not exist, an OSError is raised.

Syntax

The syntax for the mkdir() method is as follows:

os.mkdir(path[, mode])

Parameters

Return Value

This method does not return any value.

Example

The following example demonstrates the use of the mkdir() method:

#!/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")

Executing the above program will output:

Directory created

Python3 OS File/Directory Methods

❮ Ref Random Randint Python String Isdigit ❯