Python 的 divmod(~)
方法接受兩個數字並返回一個由它們的商和餘數組成的元組。
參數
1. a
| number
分子。
2. b
| number
分母。
返回值
由整數除法的商和餘數組成的元組。
例子
要返回 9
除以 4
的商和餘數:
divmod(9, 4)
(2, 1)
我們可以看到除法的商是2
,餘數是1
。
要返回 8.0
除以 2.5
的商和餘數:
divmod(8.0, 2.5)
(3.0, 0.5)
我們可以看到除法的商是3.0
,餘數是0.5
。
相關用法
- Python divmod()用法及代碼示例
- Python NumPy divmod方法用法及代碼示例
- Python NumPy divide方法用法及代碼示例
- Python distributed.protocol.serialize.register_generic用法及代碼示例
- Python distributed.get_task_metadata用法及代碼示例
- Python distributed.Client.gather用法及代碼示例
- Python distributed.recreate_tasks.ReplayTaskClient.recreate_task_locally用法及代碼示例
- Python distributed.diagnostics.plugin.SchedulerPlugin用法及代碼示例
- Python distributed.Client.ncores用法及代碼示例
- Python distributed.Client.retire_workers用法及代碼示例
- Python distributed.Client.unregister_worker_plugin用法及代碼示例
- Python distributed.fire_and_forget用法及代碼示例
- Python dir用法及代碼示例
- Python distributed.Client.set_metadata用法及代碼示例
- Python dictionary cmp()用法及代碼示例
- Python distributed.Client.scheduler_info用法及代碼示例
- Python distributed.Client.submit用法及代碼示例
- Python distributed.Client.compute用法及代碼示例
- Python distributed.SpecCluster.scale用法及代碼示例
- Python distributed.get_worker用法及代碼示例
- Python distributed.SpecCluster.scale_up用法及代碼示例
- Python difflib.unified_diff用法及代碼示例
- Python distributed.Client.nthreads用法及代碼示例
- Python distributed.comm.resolve_address用法及代碼示例
- Python distributed.Client.unpublish_dataset用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 Python | divmod method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。