true division
Division with the / operator, which always gives a float, even when the answer is whole: 6 / 3 is 2.0.
In more detail
Python 3 made / always produce a float, removing a classic Python 2 surprise where 7 / 2 gave 3. Use // for a whole-number quotient.
Example
7 / 2 # 3.5Related terms
- floor division — Division with the // operator, which rounds the answer down to the next whole number: 7 // 2 is 3.
- remainder — What is left over after whole-number division, given by the % operator: 7 % 2 is 1.
- floating-point number — A number with a fractional part stored in binary, which can only approximate most decimal values.
Taught in
- Integer Arithmetic And Precedence — Hands-on Python: Complete Video Course & Book
- Division, Quotients And Remainders — Hands-on Python: Complete Video Course & Book
- Input, And Numbers Versus Digits — Hands-on Python: Complete Video Course & Book
- Floats, Division And Mixed Types — Hands-on Python: Complete Video Course & Book
- The Exception Family Tree — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- 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
- Print, Input And The Casts Between — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Fundamentals Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Control Flow 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
- Handlers, args, raise And assert — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Exceptions Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep