3
How do I use % after a markup? Ex:
print("%d texto texto 10% texto"%var_a)
3
How do I use % after a markup? Ex:
print("%d texto texto 10% texto"%var_a)
3
Just use another sign %.
a = 42
print("valor de a: %d%%" %a)
>> valor de a: 42%
3
It is not recommended by the community to use the operator %
for the concatenation of strings
for printing, since this operator is also used to perform the resto da divisão
.
This way, always use the function format
for formatting strings. There is a PEP
which deals with this subject, but I do not remember which is.
a = 42
print("valor de a: {}%".format(a))
To leave referenced, follow the link where there is the discussion about %
and format
: https://answall.com/q/262184/5878
@Andersoncarloswoss thank you so much for the reference.
Actually in Python 3.6 there are the fstrings that are much better than format- and, before them, the use of format, although more flexible, did not need to be universal, after all, you have to type much more. In new Python, it’s much simpler to write f"valor de a: {a}"
Browser other questions tagged python string
You are not signed in. Login or sign up in order to post.
Related: https://answall.com/q/128482/64969
– Jefferson Quesado