Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i print a variable without getting brackets in python [duplicate]

Tags:

python

Here is my code below if i print it directly i'm not getting any brackets or commas whereas if i store it in a variable and print the variable its getting printed in brackets.

If anyone know to print it without brackets please let me know

Code:

user_name = input('Your Name')
user_year =  int(input('Your Birth Year'))
user_age = 2021 - user_year
user_info = "Age of",user_name,"is",user_age

print(user_info)
print('Age of',user_name,'is',user_age)

Output:

Your Name Sri Govind
Your Birth Year 2005
('Age of', ' Sri Govind', 'is', 16)
Age of  Sri Govind is 16

Process finished with exit code 0
like image 669
Sri Govind Avatar asked Feb 11 '26 01:02

Sri Govind


1 Answers

Inputting the value of the variables in the string is straightforward.

String Formatting

user_info = "Age of {name} is {age}".format(name=user_name, age=user_age)

f Strings

user_info = f"Age of {user_name} is {user_age}"
like image 157
NGilbert Avatar answered Feb 13 '26 16:02

NGilbert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!