0
I’ve been studying about Python for a short time and I’ve learned to display a print value in three ways:
%
'{}'.format(exemplo)
f' {exemplo} '
There is one more way pythonic or each form is applicable in a situation?
0
I’ve been studying about Python for a short time and I’ve learned to display a print value in three ways:
%
'{}'.format(exemplo)
f' {exemplo} '
There is one more way pythonic or each form is applicable in a situation?
0
The {}.format("variavel")
is the best way. And you can perform calculations and conditions within the ()
parentese and format the output of {}
keys.
And for what reasons is best?
Because it allows simplification in code and better maintenance in the future, especially if you leave the code for another programmer to perform maintenance in the future. Python accepts another way of declaring variable, but by convention it tends to fall into disuse and remain only the "format'. I was able to help you, Anderson?
Yes, could you supplement your answer with all this information? Currently it is based on achism without any foundation. What about f-strings, what you say to them?
Then it’s not achism. At the time I read an article explaining this concept I’m not finding the link now, I may not be being exact, you’re right. I found this font https://docs.python.org/3/library/stdtypes.html?highlight=format#str.format I believe I can help you more.
I know it’s not achism, but your current answer is because you didn’t put any foundation in it. You just said "X is better," but you didn’t say why. I also invite you to read the topic What to use to format a string, %, or format?
Anderson, thank you.
Browser other questions tagged python python-3.x string
You are not signed in. Login or sign up in order to post.
ok, sorry. I hadn’t found anything like this.
– Pedro Henrique