Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Sat Dec 11 2021
- # WEBINAR: For Loops
- # We use loops to repeat actions
- # a WHILE loop... btw.. is basically an IF statement
- # that repeats as long as its condition is true
- # FOR LOOPS are used for repeating actions for every element
- # in a container like a list, string, tuple, etc...
- myList = ["Agent Scully", "Agent Mulder", "Walter Skinner", "CSM", "Mr. X"] # X-Files characters
- for item in myList:
- print(item)
- myTuple = ("Gilligan", "Castaway002", "red", "crew")
- for item in myTuple:
- print(item)
- myString = "Just sit right back and you'll hear a tale."
- for char in myString:
- print(char, end=" ") # take this into account
- print() # print(end="\n")
- print("And the next call")
- scoobiesDCT = {
- "Scooby": "a blue collar",
- "Shaggy": "green",
- "Velma": "orange",
- "Daphne": "purple",
- "Fred": "an ascot"
- }
- # nameOfDict[key] # retrieves the value for that key
- # nameOfDict[key] = value # whether that key/value pair were there before or not
- for key in scoobiesDCT:
- print("{} wears {}.".format(key, scoobiesDCT[key]))
- for n in range(0, 10): # range() creates a list-like container of a series of numbers
- print(n)
- for i in range(len(myList)):
- # print(i)
- # item = myList[i]
- print("{} - {}".format(i, myList[i]))
- for i, item in enumerate(myList):
- print("{} --- {}".format(i, item))
- for k, v in scoobiesDCT.items():
- print("{} ALWAYS wears {}.".format(k, v))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement