remainder
What is left over after whole-number division, given by the % operator: 7 % 2 is 1.
In more detail
n % 2 == 0 is the usual test for an even number. For any numbers, a == (a // b) * b + a % b. In Python the remainder takes the sign of the divisor, so -7 % 2 is 1, which differs from some other languages.
Example
17 % 5 # 2Related terms
- floor division — Division with the // operator, which rounds the answer down to the next whole number: 7 // 2 is 3.
- arithmetic operator — A symbol that does arithmetic on numbers: + add, - subtract, * multiply, / divide, // floor divide, % remainder and ** power.
Taught in
- Division, Quotients And Remainders — Hands-on Python: Complete Video Course & Book
- Input, And Numbers Versus Digits — Hands-on Python: Complete Video Course & Book
- The String Format Method — Hands-on Python: Complete Video Course & Book
- Floats, Division And Mixed Types — Hands-on Python: Complete Video Course & Book
- Thirty Questions, One Sneaky Print — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Operators And Who Binds First — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Fundamentals Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Twelve Traps, One Shape Each — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Mock, Review And Exam Day — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Sixty Five Minutes, Forty Items: How PCAP Is Run — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Import Variants, dir() And sys.path — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- List Comprehensions, Filtered And Nested — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Lambdas, map() And filter() — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Generators And Iterators — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Comprehensions, Closures And Files Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Mock, Review And Exam Day — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep