Python is a bit different in its usage of the %
operator, which really computes the modulo of two values, whereas other programming languages compute the remainder with the same operator. For example, the distinction is clear in Scheme:
(modulo -1 4) ; modulo => 3 (remainder -1 4) ; remainder => -1
In Python:
-1 % 4 # modulo => 3 math.fmod(-1, 4) # remainder => -1
But in OCaml, there’s only mod
(which computes the integer remainder), according to this table and as stated in the documentation:
-1 mod 4 (* remainder *) => -1
Of course, you can implement your own modulo
operation in terms of remainder
, like this:
let modulo x y = let result = x mod y in if result >= 0 then result else result + y
Related Posts:
- Does Python have a ternary conditional operator?
- Is there a “not equal” operator in Python?
- What is the result of % in Python?
- Is there a “not equal” operator in Python?
- What do these operators mean (** , ^ , %, //)? [closed]
- What do these operators mean (** , ^ , %, //)? [closed]
- proper name for python * operator?
- What does the power operator (**) in python translate into?
- What does the percentage sign mean in Python
- The tilde operator in Python
- What does the percentage sign mean in Python
- What is the difference between ‘/’ and ‘//’ when used for division?
- How do I correctly use the mod operator in MIPS?
- Using the AND and NOT Operator in Python [duplicate]
- Python a &= b meaning?
- Python ‘If not’ syntax [duplicate]
- What is the maximum recursion depth in Python, and how to increase it?
- How to change the order of DataFrame columns?
- What does %s mean in a python format string?
- ImportError: No module named ‘tensorflow.python’
- How to access environment variable values
- python numpy ValueError: operands could not be broadcast together with shapes
- error: command ‘gcc’ failed with exit status 1 while installing eventlet
- Python foreach equivalent
- Python NoneType object is not callable (beginner)
- _tkinter.TclError: no display name and no $DISPLAY environment variable
- What does if __name__ == “__main__”: do?
- How to fix IndexError: invalid index to scalar variable
- How to write inline if statement for print?
- Could not install packages due to a “Environment error :[error 13]: permission denied : ‘usr/local/bin/f2py'”
- ^=, -= and += symbols in Python
- How does numpy.newaxis work and when to use it?
- How to move a file in Python?
- proper name for python * operator?
- TypeError: cannot unpack non-iterable int objec
- Why are Python’s ‘private’ methods not actually private?
- Pandas DataFrame column to list
- Error: ” ‘dict’ object has no attribute ‘iteritems’ “
- Does Python have “private” variables in classes?
- Rename Pandas DataFrame Index
- How to upgrade pip3?
- Is module __file__ attribute absolute or relative?
- How do I convert a list of ascii values to a string in python?
- Why do I get a “referenced before assignment” error when assigning to a global variable in a function?
- Is there a way to perform “if” in python’s lambda?
- Remove the first character of a string
- Difference in output with waitKey(0) and waitKey(1)
- Overcome ValueError for empty array
- Python list directory, subdirectory, and files
- Parsing boolean values with argparse
- Running Jupyter via command line on Windows
- Using Pip to install packages to Anaconda Environment
- How do I convert hex to decimal in Python?
- What is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv, etc?
- How to get all subsets of a set? (powerset)
- Python throws ValueError: list.remove(x): x not in list
- ‘int’ object has no attribute ‘__getitem__’
- Selecting/excluding sets of columns in pandas
- How to add title to seaborn boxplot
- Pygame mouse clicking detection
- How to update SQLAlchemy row entry?
- Create an empty list in Python with certain size
- What is the perfect counterpart in Python for “while not EOF”
- Numpy.dot TypeError: Cannot cast array data from dtype(‘float64’) to dtype(‘S32’) according to the rule ‘safe’
- NumPy array is not JSON serializable
- How to XOR two strings in Python
- What’s the difference between lists enclosed by square brackets and parentheses in Python?
- python is not recognized windows 10
- Haversine Formula in Python (Bearing and Distance between two GPS points)
- How to join on multiple columns in Pyspark?
- How can I login to a website with Python?
- function is not defined error in Python
- Need to install urllib2 for Python 3.5.1
- Django reverse lookup of foreign keys
- If list index exists, do X
- ImportError: No module named ‘xlrd’
- How to repeat a string with spaces?
- NameError: name ‘requests’ is not defined
- Seaborn Lineplot Module Object Has No Attribute ‘Lineplot’
- kernel keeps dying in jupyter notebook
- Superscript in Python plots
- threshold in 2D numpy array
- What is the difference between ‘SAME’ and ‘VALID’ padding in tf.nn.max_pool of tensorflow?
- Is it possible to use ‘else’ in a list comprehension?
- How to randomly get 0 or 1 every time?
- jinja2.exceptions.TemplateNotFound error [duplicate]
- Loading and parsing a JSON file with multiple JSON objects
- How to get ° character in a string in python?
- Mutable strings in Python
- Inserting image into IPython notebook markdown
- Writing Python lists to columns in csv
- python’s re: return True if string contains regex pattern
- How to implement the –verbose or -v option into a script?
- Difference between modes a, a+, w, w+, and r+ in built-in open function?
- How can I color part of Slack incoming-webhook messages?
- How to import or include data structures (e.g. a dict) into a Python file from a separate file
- In python, how can I print lines that do NOT contain a certain string, rather than print lines which DO contain a certain string:
- input() error – NameError: name ‘…’ is not defined
- A very basic setting issue about spyder and anaconda for python
- ImportError: No module named BeautifulSoup