+ 3

Why and how, second one is more powerful then 1st one

print("your:" +a) print("your:" .format(a=12)

4th Aug 2020, 5:27 PM
Angus👑
Angus👑 - avatar
4 Answers
+ 12
There are several options recommended to make an ouput look formatted: name = 'Paul' print('Your name is ' + name) print('Your name is', name) print(f'Your name is {name}') The first and the second are sufficient for simple output, the third is f-string and a real powerful version. Find some information and a comparison of formatting output: https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-formatted-output/
4th Aug 2020, 5:50 PM
Lothar
Lothar - avatar
+ 8
You'll have a better and self-explaining example, if you put three parameters of different data types at three different places within a message: how_many = 5; what = "apples"; cost = 4.99; print("I want to buy " + str(how_many) + what + " for " + str(cost) + " dollars"); print(f"I want to buy {how_many} {what} for {cost} dollars"); print("I want to buy {how_many} {what} for {cost} dollars".format(how_many = 3, what = "bananas", cost = 2.99));
4th Aug 2020, 5:44 PM
Sandra Meyer
Sandra Meyer - avatar
+ 3
Lothar Sandra Meyer I'm really sorry for this late reply since I was reading some documentation as Lothar suggested in previous post and very thankful to both of you from my bottom of my heart 💓, always help me in this manner, and here's some of code if I'm unable to say thank you in future but upvote is for sure https://code.sololearn.com/ctyd028qg7U9/?ref=app
4th Aug 2020, 6:33 PM
Angus👑
Angus👑 - avatar
+ 2
Aww, that's cute Angus👑
4th Aug 2020, 6:34 PM
minirkk
minirkk - avatar