Skip to content

Instantly share code, notes, and snippets.

@rmorenobello
Last active October 20, 2022 17:43
Show Gist options
  • Save rmorenobello/c2aca824092fb2febfba70d55a533889 to your computer and use it in GitHub Desktop.
Save rmorenobello/c2aca824092fb2febfba70d55a533889 to your computer and use it in GitHub Desktop.
Python - Strings
# Remember str are immutable objects
# IMPORTANT: only worth it for really long strings!
# otherwise just use +=
# Summary: Append them to a list, join them with "".join()
charlist = []
text = ''
# it would also work for words, sentences, ...
for char in text_to_loop:
charlist.append(char)
# we construct the string with the optimized str.join() method:
text = "".join(charlist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment