Python Visualizing your code
Visualizing Your Code
When you're first learning about data structures such as lists, it helps to visualize how python is working with the information in your program. pythontutor.com is a graet tool for seeing how python keeps track of the information in a list. Try running the following code on pythontutor.com and then run your own code.
#Build a list and print the items in the list
dogs = []
dogs.append('willie')
dogs.append('hootz')
dogs.append('peso')
dogs.append('goblin')
for dog in dogs:
print("Hello " + dog + "!")
print("I love these dogs!")
print("\nThese were my first two dogs:")
old_dogs = dogs[:2]
for old_dog in old_dogs:
print(old_dog)
del dogs[0]
dogs.remove('peso')
print(dogs)
No comments:
Post a Comment