for i in str1:
(newstr += chr(ord(i)+2)) if i.isalpha() else (newstr += i)
It seems to be grieving about the += operator. I know both my variables are strings though, so I don't understand why it would not just concatenate them
Try the following:
for i in str1:
newstr += (chr(ord(i)+2) if i.isalpha() else i)
Edit:
From python documentation:
conditional_expression ::= or_test ["if" or_test "else" expression]
expression ::= conditional_expression | lambda_expr
And as pointed by @flornquake, the assignment var += value is a statement, not an expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With