[Python Basics] Working With Lists — Part 1

We practice how to loop over some lists using a few lines of code regardless of how long the lists are.

Photo by Lysander Yuen on Unsplash

Looping Over an Entire List

my_string = "Hello, my Python!"  #1
my_list = list(my_string) #2
for item in my_list: #3
print(item.upper()) #4
for item in my_list:
    print(item.upper())
my_string = "Hello, my Python!"  #1
my_list = list(my_string) #2
for item in my_list: #3
print(item.upper()) #4
print("processed") #5
my_string = "Hello, my Python!"  #1
my_list = list(my_string) #2
for item in my_list: #3
print(item.upper()) #4
print("Finally, I'm done.") #5

Common Errors

my_string = "Hello, my Python!"  #
my_list = list(my_string) #
for item in my_list # Colon : is missing here.
print(item.upper()) #
my_string = "Hello, my Python!"  #
my_list = list(my_string) #
for item in my_list: #
print(item.upper()) # We need spaces.
my_string = "Hello, my Python!"  #
my_list = list(my_string) #
for item in my_list: #
print(item.upper()) #
print('Done') # We need spaces here too or not.

--

--

Ydobon is nobody.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store