Why do I get an error with print(f"({x}, {y})")?
Question:
for x in range(5):
for y in range(3):
print(f"({x}, {y})")
I was trying to follow along in a python mastery class but I kept getting the following error.
File "c:Users███DesktopPy ProductsTutorialHelloWorldapp.py", line 3
print(f"({x}, {y})")
^
SyntaxError: invalid syntax
Answers:
you are trying to format the string while printing so you can use
for x in range(5):
for y in range(3):
print('{}, {}'.format(x, y))
for x in range(5):
for y in range(3):
print(f"({x}, {y})")
I was trying to follow along in a python mastery class but I kept getting the following error.
File "c:Users███DesktopPy ProductsTutorialHelloWorldapp.py", line 3
print(f"({x}, {y})")
^
SyntaxError: invalid syntax
you are trying to format the string while printing so you can use
for x in range(5):
for y in range(3):
print('{}, {}'.format(x, y))