In this article, we are going to learn all about the Python oct() function to convert an integer to an octal string. In previous tutorials, we have seen various Python built-in functions tutorials along with examples.
Headings of Contents
Python oct() Function Introduction
Python oct() function is a Python built-in function which means you don’t need to install it by using the pip command or no need to import from any module. oct() function in Python is used to convert any integer number to octal.
The syntax of oct() function in python is:-
oct() function in Python takes a single parameter that is an integer number. It will return TypeError if any other value will be passed other than an integer.
Python oct() function Example
In this section, I am going to explore the oct function along with multiple examples so that you can get more clarity with the oct() function.
Example: Converting Decimal to Octal
# Deciaml to Octal print('oct(10) is:', oct(10))
oct(10) is: 0o12
Example: Converting Hexadecimal to Octal
# Hexadecimal to Octal print('oct(0XB) is:', oct(0XB))
oct(0XB) is: 0o13
In this article, you have learned all about the oct() function to convert any integer to an octal number. It is also capable of converting any decimal and hexadecimal value to octal.
If you like this article, please share and keep visiting for further python built-in functions tutorials.
Python built-in functions
For more information:- Click Here
Reference:- Click Here
Thanks for your valuable time…❤️❤️