Code Yarns β€πŸ‘¨β€πŸ’»
Tech Blog ❖ Personal Blog

Python: Division operator gotcha

πŸ“… 2009-Oct-14 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ division, python ⬩ πŸ“š Archive

/ does true division by default in Python 3

# Use // for integer (or floor) division
# See PEP 238 for details
inta = 5
intb = 3
intc = inta / intbΒ  # 1.6666666666666667
intd = inta // intb # 1

Β© 2022 Ashwin Nanjappa β€’ All writing under CC BY-SA license β€’ 🐘 @codeyarns@hachyderm.io β€’ πŸ“§