Some more advanced Python builtins
#

enumerate
#

enumerate
is useful when you are iterating over a list, and you want access to both the index and the value.

string = "hello world"
for idx, char in enumerate(string):
  print(idx, char)

# output:
# 0 h
# 1 e
# 2 l
# ...snip...

zip
#

zip
is useful if you have two lists that you want to iterate over together. Note that if the lists are different lengths,
zip
will stop at the length of the shorter list.

names = ["matt", "john", "susan"]
grades = ["B", "C", "A"]

for name, grade in zip(names, grades):
  print(name, grade)

# output:
# matt B
# john C
# susan A

f-strings
#

f-strings are Python's improved syntax for format strings, which make printing much more convenient. Read more about the history of format strings and format string specifiers here.

name = "matt"
year = "2022"
gpa  = 3.9

print(f"{name.upper()} is in the Class of {year} and has a GPA of {gpa:.2f}.")

# output:
# MATT is in the Class of 2022 and has a GPA of 3.90.