Last active
May 7, 2022 02:18
-
-
Save altela/42686e68454e697d0a7ff9ef4191b4fc to your computer and use it in GitHub Desktop.
Python FOR Iteration tricks
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
# Add character inside list | |
list_numbers = ['001','002','003'] | |
add_percent = [pulled + "%" for pulled in list_numbers] | |
print(add_percent) | |
# The result will be ['001%','002%','003%'] | |
# Split each words with space | |
# Example 1 | |
the_string = 'silly walks' | |
for ix in range(len(the_string)): | |
print(the_string[ix], end=' ') | |
print(ix) | |
# Example 2 | |
the_string = 'silly walks' | |
for words in the_string : | |
print(words, end=" ") | |
print(words) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment