divmod – division and modulus together in Python

divmod is a wonderful, nice, little built-in function in Python that allows you to do division and modulus operation together. Using it, you can make your code slightly beautiful, thus Pythonic! Check the following example –

>>> 10 / 3
3.3333333333333335
>>> 10 // 3
3
>>> 10 % 3
1
>>> divmod(10, 3)
(3, 1)

Read the entire article at the source link… Tamim Shahriar

#codango #developer #development #coder #coding

We're happy to share this resource that we found. The content displayed on this page is property of it's original author and/or their organization.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*