{"id":24835,"date":"2021-11-02T09:54:25","date_gmt":"2021-11-02T04:24:25","guid":{"rendered":"https:\/\/python-programs.com\/?p=24835"},"modified":"2021-11-05T20:38:13","modified_gmt":"2021-11-05T15:08:13","slug":"python-oct-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-oct-function-with-examples\/","title":{"rendered":"Python oct() Function with Examples"},"content":{"rendered":"

In the previous article, we have discussed Python min() Function with Examples<\/a>
\noct() Function in Python:<\/strong><\/p>\n

The oct() function is used to convert an integer to an octal string.<\/p>\n

Python prefixes octal strings with 0o.<\/p>\n

Syntax:<\/strong><\/p>\n

oct(number)<\/pre>\n

Parameters<\/strong><\/p>\n

number:<\/strong> This is required. It is an integer number.<\/p>\n

If the value is not an integer (binary, decimal, or hexadecimal), it should implement __index__() to return an integer.<\/p>\n

Return Value:<\/strong><\/p>\n

The oct() function takes an integer number and returns an octal string.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given Number = 18<\/pre>\n

Output:<\/strong><\/p>\n

The given number's{ 18 } Octal Value =  0o22\r\nThe oct() function Return Type = <class 'str'><\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given number\u00a0 = 13\r\nGiven binary number\u00a0 = 0b10\r\nGiven hexadecimal number\u00a0 = 0XB<\/pre>\n

Output:<\/strong><\/p>\n

The oct(13) value is =  0o15\r\nThe oct(0b10) value =  0o2\r\nThe oct(0XB) value =  0o13<\/pre>\n

oct() Function with Examples in Python<\/h2>\n