print a variable [closed]

0

For example:

edad = 18

print("Tengo %d años) % edad

According to what they told me, I had to formulate it like this but I'm getting this error:

  

TypeError: unsupported operand type (s) for%: 'NoneType' and 'int'

    
asked by Ariel 07.06.2018 в 08:06
source

2 answers

1

The syntax is

edad = 18
print("tengo %d años" % edad)

And it does work in python3.

    
answered by 07.06.2018 в 15:28
-1

In Python 3.x the use of% is no longer allowed.

Edit

In link I read

  

A new system for built-in string formatting operations replaces the% string formatting operator. (However, the% operator is still supported; it will be deprecated in Python 3.1 and removed from the language at some later time.)   Read PEP 3101 for the full scoop.

End

You must use .format.

For example in your case:

edad=18
frase="Tengo {} años".format(edad)
print(frase)
    
answered by 07.06.2018 в 08:40