Python Quick Notes
This article is a list of quitck notes or a cheat sheet for myself. Here you will find the actions I use the most when programming stuff with Python and that my fish memory doesn’t allow to retain.
Python Loops
While Loop
colors = ["red", "green", "blue", "purple"]
i = 0
while i < len(colors):
print(colors[i])
i += 1
Range of length
colors = ["red", "green", "blue", "purple"]
for i in range(len(colors)):
print(colors[i])
for-in
colors = ["red", "green", "blue", "purple"]
for color in colors:
print(color)
If indexes are needed
Range of length
pr```
esidents = ["Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson"]
for i in range(len(presidents)):
print("President {}: {}".format(i + 1, presidents[i]))
Enumerate
presidents = ["Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson"]
for num, name in enumerate(presidents, start=1):
print("President {}: {}".format(num, name))