Nie można dowiedzieć się, jak działa podstawianie String w Pythonie 3.x [zamknięte]
W pythonie 2.x pozwolono ci zrobić coś takiego:
>>> print '%.2f' % 315.15321531321
315.15
Jednak nie mogę go uruchomić w Pythonie 3.x, próbowałem różnych rzeczy, takich jak
>>> print ('%.2f') % 315.15321531321
%.2f
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for %: 'NoneType' and 'float'
>>> print ("my number %") % 315.15321531321
my number %
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for %: 'NoneType' and 'float'
Następnie przeczytałem o metodzie .format (), ale też nie mogę jej uruchomić
>>> "my number {.2f}".format(315.15321531321)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'float' object has no attribute '2f'
>>> print ("my number {}").format(315.15321531321)
my number {}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'format'
Byłbym szczęśliwy z wszelkich wskazówek i sugestii!