×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python divmod() Function: Use, Syntax, and Examples

By IncludeHelp Last updated : December 07, 2024

Python divmod() function

The divmod() function is a library function in Python, it is used to get the quotient and remainder of given values (dividend and divisor), it accepts two arguments: dividend and divisor, and returns a tuple that contains quotient and remainder.

Syntax

The following is the syntax of divmod() function:

divmod(dividend, divisor)

Parameter(s):

The following are the parameter(s):

  • dividend – a number to be divided.
  • divisor – a number to be divided with.

Return Value

The return type of divmod() function is <class 'tuple'>, it returns a tuple containing quotient and remainder.

Python divmod() Function: Example 1

# Example of Python divmod() Function

x = 10
y = 3
print(divmod(x, y))

x = 21
y = 7
print(divmod(x, y))

Output

(3, 1)
(3, 0)

Python divmod() Function: Example 2

Python code to find quotient and remainder of two numbers.

# python code to demonstrate example of 
# divmod() number

a = 10  #dividend
b = 3   #divisor

print("return type of divmod() function: ", type(divmod(a,b)))

# finding quotient and remainder
result = divmod(a,b)
print("result = ", result)

# float values
a = 10.23  #dividend
b = 3.12   #divisor

# finding quotient and remainder
result = divmod(a,b)
print("result = ", result)

Output

return type of divmod() function:  <class 'tuple'>
result =  (3, 1)
result =  (3.0, 0.8700000000000001)
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement



Copyright © 2024 www.includehelp.com. All rights reserved.