Skip to content

Instantly share code, notes, and snippets.

@martin-martin
Last active June 10, 2018 12:18
Show Gist options
  • Save martin-martin/541835318a3d3c878607f7d4681e9251 to your computer and use it in GitHub Desktop.
Save martin-martin/541835318a3d3c878607f7d4681e9251 to your computer and use it in GitHub Desktop.
CheerySoreSequel created by martin_martin - https://repl.it/@martin_martin/CheerySoreSequel
name = 'codingnomads'
# trying to change the string directly causes an error
# name[8:] = 'rmals'
# TypeError: 'str' object does not support item assignment
# we need to create a new string
new_name = name[:8] + 'rmals' # using string slicing and concatenation
print(name, new_name)
# after re-assigning the value, the old 'name' is overwritten
name = new_name
print(name, new_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment