Python - How to carry out string operations? -


code:

str="hello world"          in range(len(str)):                     str[i]=str[len(str)-i]     print(str) 

this corresponds error in python. right way implement this?

  1. in python, strings immutable. can't reassign individual characters.
  2. str not variable name because masks built-in function str().
  3. it looks want reverse string:

string = "hello world" reversed_string = string[::-1] 

Comments