--- warning: This file is auto generated by `yarn web:inject`, do not edit by hand examples: - mod(7, 3) - mod(-7, 3) returns: - '1' - '2' dependencies: - python/_helpers/_operator authors: original by: - Kevin van Zonneveld (https://kvz.io) notes: - >- Uses Python's modulo semantics, where the remainder follows the divisor sign. parityVerified: - Python 3.12 isTypescript: true type: function layout: function title: Python's operator.mod in TypeScript description: >- Here's what our current TypeScript equivalent to Python's operator.mod looks like. function: mod category: operator language: python permalink: python/operator/mod/ alias: - /functions/python/mod/ - /functions/operator/mod/ - /python/mod/ ---
{% codeblock lang:typescript %}import { pythonMod } from '../_helpers/_operator.ts' export function mod(a: unknown, b: unknown): number { // discuss at: https://locutus.io/python/operator/mod/ // parity verified: Python 3.12 // original by: Kevin van Zonneveld (https://kvz.io) // note 1: Uses Python's modulo semantics, where the remainder follows the divisor sign. // example 1: mod(7, 3) // returns 1: 1 // example 2: mod(-7, 3) // returns 2: 2 return pythonMod(a, b, 'mod') } {% endcodeblock %}