How to display multiline text with format?

1

I'm trying for several consecutive lines with a single string along with the .format method, but I can not.

a=input("digite algo; ")
print("""contem maiusculos:{}  contem: {}n\contem números: {}  contem
alfanumericos: {}""".format(a.isupper(),a.isnumeric(),a.isalnum()))

In case, it is giving error because it is out of scope, but I have tried it in other ways, but it always ends up that I can not use the .format method or only partially.

In this case I will still need more line, as I will use more methods than those already listed in the example.

    
asked by anonymous 30.10.2017 / 18:46

1 answer

4

From what I understand, you want the output to be displayed in multiple lines. As it stands, it results in the error:

  

IndexError: tuple index out of range

For the simple fact that your string expects 4 values to be formatted correctly and you pass only 3. Therefore, such an error would be supplied by passing the fourth parameter to format , whatever it is. / p>

The problem of line breaking is apparently because you attempted to break the line with n\ , while the break line character is \n . But using the string between three quotation marks, as you are doing, there is no need to use such a character. The line break itself in string will break the line in the output.

See an example:

a = input("Digite algo: ")

saida = """
Você digitou: {}
O texto possui {} caracteres
O texto é um valor numérico? {}
"""

print(saida.format(a, len(a), a.isnumeric()))

See working at Ideone | Repl.it

Output Examples:

>>> Digite algo: Anderson Carlos Woss

Você digitou: Anderson Carlos Woss
O texto possui 20 caracteres
O texto é um valor numérico? False

>>> Digite algo: 2017

Você digitou: 2017
O texto possui 4 caracteres
O texto é um valor numérico? True
    
01.11.2017 / 21:54