Skip to content

Instantly share code, notes, and snippets.

@drincruz
Created August 22, 2014 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drincruz/4d5c0f9ba40bc58454fc to your computer and use it in GitHub Desktop.
Save drincruz/4d5c0f9ba40bc58454fc to your computer and use it in GitHub Desktop.
Appending to a Python string
"""
There are multiple ways to append to a string in Python
"""
str0 = "This is my string"
# Use the + operator
str0 = str0 + ". This is now appended to the string"
# Use a list to append
list_str0 = list(str0)
list_str0.append(". NOW this is appended again.")
list_str0.append(" AND this is also appended.")
# Convert it back to a string
"".join(list_str0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment