Created
August 22, 2014 16:31
-
-
Save drincruz/4d5c0f9ba40bc58454fc to your computer and use it in GitHub Desktop.
Appending to a Python string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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