
PRO
Elvis
asked

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.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer