Answered by Martijn Pieters. Thank you.
It is because statement vs expression.
And because .join() does not mutate (is a pure function), so it needs to be assigned to a variable.
Question:
What is the reason for this oddity?
Goal:
if base == 'T':
RNA_seq += 'U'
else:
RNA_seq += base
This following method works:
# += in expression1 and .join() in expression2
RNA_seq += 'U' if base == 'T' else RNA_seq.join(base)
# Edit note: RNA_seq.join(base) works because it returns `base`
# aka. RNA_seq += 'U' if base == 'T' else base
However the following does NOT work:
# Using += on both expressions
RNA_seq += 'U' if base == 'T' else RNA_seq += base
or
# Using .join() for both expressions
RNA_seq.join('U') if base == 'T' else RNA_seq.join(base)
The results are the same in both Python2 and Python3.