- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
How does modulus work with complex numbers in Python?
Floor and modulus operators (// and % respectively) are not allowed to be used on complex number in Python 3.x. However, these operations are defined for complex numbers in Python 2.7.x
>>> x=9+2j >>> y=2+1j >>> x%y Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> x%y TypeError: can't mod complex numbers.
>>> x=9+2j >>> y=2+1j >>> x%y (1-2j)
Modulus of complex number operands returns their floor division multiplied by denominator
>>> x-(x//y)*y (1-2j)
- Related Articles
- Complex Numbers in Python?
- How does linear regression work with Tensorflow in Python?
- How to Plot Complex Numbers in Python?
- How can we use complex numbers in Python?
- How does tuple comparison work in Python?
- How does underscore "_" work in Python files?
- How does garbage collection work in Python?
- How does class inheritance work in Python?
- How does issubclass() function work in Python?
- How does isinstance() function work in Python?
- How does Overloading Operators work in Python?
- How does ++ and -- operators work in Python?
- How does Python's super() work with multiple inheritance?
- Python program for Complex Numbers
- Modulus of Negative Numbers in C