python - What is wrong with this ternary operator? -
for in str1: (newstr += chr(ord(i)+2)) if i.isalpha() else (newstr += i)
it seems grieving += operator. know both variables strings though, don't understand why not concatenate them
try following:
for 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 pointed @flornquake, assignment var += value
statement, not expression.
Comments
Post a Comment