Last active
October 20, 2022 17:43
-
-
Save rmorenobello/c2aca824092fb2febfba70d55a533889 to your computer and use it in GitHub Desktop.
Python - Strings
This file contains hidden or 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
# 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