enumerate
enumerate
string = "hello world"
for idx, char in enumerate(string):
print(idx, char)
# output:
# 0 h
# 1 e
# 2 l
# ...snip...
zip
zip
zip
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 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.