12080 instead of 200 — I laughed out loud

BellaRossiOP

Never seen addition produce that. So "120" + "80" just glues the text together?

10

Comments 4

Join the discussion

Already have an account? Log in

  1. EmmaCodesreplies: 2

    Yep, + on strings means concatenation. Data from sensors, files, input() and APIs often arrives as text, so converting with int() or float() is step one.

    1
    1. BellaRossiOPreplies: 1

      That explains a bug I had in an actual spreadsheet export script last month.

      2
      1. OliviaPy

        And for decimals in stage 3, float(), not int() — int("98.5") throws an error.

        5
    2. ZosiaN

      type() is your best friend whenever numbers act weird.

      2