How python oct(), ord() and pow() function works?

Python oct() Function

Python oct() function is used to get an octal value of an integer number. This method takes an argument and returns an integer converted into an octal string. It throws an error TypeError , if argument type is other than an integer.

Python oct() function Example

# Calling function  
val = oct(10)  
# Displaying result  
print("Octal value of 10:",val)  

Output:

Octal value of 10: 0o12

Python ord() Function

The python ord() function returns an integer representing Unicode code point for the given Unicode character.

Python ord() function Example

# Code point of an integer  
print(ord('8'))  
  
# Code point of an alphabet   
print(ord('R'))  
  
# Code point of a character  
print(ord('&'))  

Output:

56
82
38

Python pow() Function

The python pow() function is used to compute the power of a number. It returns x to the power of y. If the third argument(z) is given, it returns x to the power of y modulus z, i.e. (x, y) % z.

Python pow() function Example

# positive x, positive y (x**y)  
print(pow(4, 2))  
  
# negative x, positive y  
print(pow(-4, 2))  
  
# positive x, negative y (x**-y)  
print(pow(4, -2))  
  
# negative x, negative y  
print(pow(-4, -2))  

Output:

16
16
0.0625
0.0625