My Day✳All blog articles ↗

Separate numeric addition from string concatenation

Record both value and type: similar-looking symbols can take part in different operations.

Python’s + depends on operand types. With integers it adds values; with strings it joins text. In a study trace, read the quotation marks first, then record the value together with its type. A string containing digits does not automatically become a number.

2 numeric operands → int 5; 2 string operands → str "23".
2 numeric operands → int 5; 2 string operands → str "23".

What to do

  1. Mark which operands are numeric literals and which are enclosed in quotation marks.
  2. Trace each expression separately and label its result as int or str.
  3. Check both value and type against the original, preserving quotes around the string result.

Example

Fictional card: a=2+3; b="2"+"3". For a, the result is 5 of type int. For b, it is "23" of type str, not numeric 23. Diagram [2,2] counts 2 numeric and 2 string operands, not result magnitudes. This is a manual Python trace.

My Day · Windows

In My Day, manually save the check and your next action; verify the source yourself.

Buy My Day for Windows ↗