When you do:
print('{} é', type(n1), 'além disso, ele é'.format(n1))
You’re passing 3 arguments to print
, since they are separated by comma:
- the string
'{} é'
- the result of
type(n1)
- the result of
'além disso, ele é'.format(n1)
They are 3 "independent" values, that is, each of them is passed separately, and print
prints one by one.
That means that the method format
is only applied to the string 'além disso, ele é'
, and how you don’t have the placeholder {}
in this string, there is nothing to replace.
Anyway, an alternative to your case is to put everything in a single string and call format
passing the values you want:
print('o valor da variável é {}, e seu tipo é {}'.format(n1, type(n1)))
Or, if you’re using Python >= 3.6, you can use f-string:
print(f'o valor da variável é {n1}, e seu tipo é {type(n1)}')
Note the "f" before the quotation marks, this indicates that it is an f-string and that I can put the figures to be printed inside the brackets.
Please try to better formulate your question. See these links on how to ask questions here https://pt.meta.stackoverflow.com/questions/8388/que-erro-eu-cometi-fazendo-minha-perguntar?cb=1 and here https://pt.meta.stackoverflow.com/questions/8089/guia-de-sobreviv%C3%aancia-do-sopt-vers%C3%a3o-curta? cb=1. For example: in the question title, put your question so that people already identify what you need. You also need to tag the language you are using. See other questions and try to follow the templates.
– RxT