Também daria para apresentar uma string usando repr. :D
repr
Exemplo:
print(f'A string {nome_completo!r} tem {tamanho} letras.') # A string 'Danielle Farias' tem 14 letras.
Não sabia! Vou pesquisar sobre. Obrigada pela dica. ;)
Vou deixar comentado aqui pra facilitar:
Na documentação da linguagem de formatação tem um trecho onde diz:
If a conversion is specified, the result of evaluating the expression is converted before formatting. Conversion '!s' calls str() on the result, '!r' calls repr(), and '!a' calls ascii().
Que basicamente diz que:
f"{variavel!r} == repr(variavel)
f"{variavel!s} == str(variavel)
f"{variavel!a} == ascii(variavel)
Qualquer dúvida o site PyFormat tem bastante coisa legal.
Obrigada!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Também daria para apresentar uma string usando
repr
. :DExemplo:
Não sabia! Vou pesquisar sobre. Obrigada pela dica. ;)
Vou deixar comentado aqui pra facilitar:
Na documentação da linguagem de formatação tem um trecho onde diz:
Que basicamente diz que:
f"{variavel!r} == repr(variavel)
(#docs)f"{variavel!s} == str(variavel)
(#docs)f"{variavel!a} == ascii(variavel)
(#docs)Qualquer dúvida o site PyFormat tem bastante coisa legal.
Obrigada!