Code Yarns ‍👨‍💻
Tech BlogPersonal 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

© 2026 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 Mastodon🦋 Bluesky📧 Email