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)

Comments

Popular posts from this blog

Get next element from a list in Python

Convert text to ASCII and ASCII to text - Python code

Use Proxy in your Spider