Python Forum

Full Version: Using .format() with expresions.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am new to Python and have been trying to trim some code for brevity.
Following is the original code.
user_sentance = input("Enter a sentance. ")
user_character = input("Enter a character. ")
index = user_sentance.find(user_character)
print("{} is at index {}.".format(user_character, index))
Then I try to replace the print() statement with:
print("{} is at index {}.".format(user_character, user_sentance.find(user_character))
I get an invaled syntax error.
Why does this not work? What am I missing?

Python 3.8
macOS Catalina
You are missing a close parenthesis at the end of the line.
f-string is better yet:
print(f"{user_character} is at index {index}")