[python] Get quotient and remainder

Try to get quotient and remainder at the same time

point

--Use divmod

n = 3
cnt = 10
quot, mod = divmod(cnt, n)
#quotient
print(quot)
#Surplus
print(mod)
>>> #quotient
>>>
>>> print(quot)
3
>>> #Surplus
>>>
>>> print(mod)
1
>>>

Take the quotient and the remainder separately

point

--Commercial //` ` --Remainder `` `%

n = 3
cnt = 10
#quotient
print(cnt // n)
#Surplus
print(cnt % n)
>>> #quotient
>>>
>>> print(cnt // n)
3
>>> #Surplus
>>>
>>> print(cnt % n)
1
>>>

Recommended Posts

[python] Get quotient and remainder
Python built-in function ~ divmod ~ Let's get the quotient and remainder of division at the same time
Get git branch name and tag name with python
Get Gmail subject and body with Python and Gmail API
[python] Compress and decompress
Python and numpy tips
[Python] pip and wheel
Batch design and python
Python iterators and generators
[Python] Get Qiita trends
Ruby, Python and map
python input and output
Python and Ruby split
[Python3] Get date diff
Get date in Python
Get date with python
Python3, venv and Ansible
Python asyncio and ContextVar
python get current time
Get your current location and user agent in Python
Get mail from Gmail and label it with Python3
Get and automate ASP Datepicker control using Python and Selenium
Get stock prices and create candlestick charts in Python
Get files from Linux using paramiko and scp [Python]
[Python] Get user information and article information with Qiita API
Get an abstract understanding of Python modules and packages
Get YouTube Comments in Python
Get country code with python
Programming with Python and Tkinter
Python --bitflyer Get asset balance
Encryption and decryption with Python
Python: Class and instance variables
3-3, Python strings and character codes
Python 2 series and 3 series (Anaconda edition)
Python and hardware-Using RS232C with Python-
Python on Ruby and angry Ruby on Python
Python indentation and string format
Get last month in python
Python real division (/) and integer division (//)
Install Python and Flask (Windows 10)
Get Twitter timeline with python
About python objects and classes
About Python variables and objects
Apache mod_auth_tkt and Python AuthTkt
Å (Ongustromu) and NFC @ Python
Get Youtube data with python
Python shallow copy and deep copy
Get the MIME type in Python and determine the file format
Python and ruby slice memo
Python installation and basic grammar
I compared Java and Python!
Python shallow and deep copy
Get a Python web page, character encode it, and display it
Get rid of dirty data with Python and regular expressions
About Python datetime and timezone
Get Terminal size in Python
Install Python 3.7 and Django 3.0 (CentOS)
[Python] Get the previous month
Python environment construction and TensorFlow
Python class variables and instance variables
Explicitly get EOF in python