A
Abhay Jajodia
Answered 1 questions
About
Answered by Abhay Jajodia

PRO
Elvis
asked
A
Expert
Abhay Jajodia answered
So, in Python, you don't need to use curly braces {}
when printing a variable like this:
name = input("Enter your name: ")
print("Your name is", name)
That works because print()
can take multiple things, separated by commas. It just puts spaces between them automatically, so you don't have to do anything fancy.
Now, curly braces do show up when you're using something like an f-string. That looks like this:
print(f"Your name is {name}")
In that case, the {name}
is inside the string, and Python replaces it with the actual value of the name
variable — but only because the string starts with an f
.
So yeah, curly braces are just for special formatting stuff like f-strings. If you're just printing normally with commas, you don’t need them at all.
Python
This question was asked as part of the Learn Python Basics course.