LINUX.ORG.RU

Python: «string {value}».format( value = 123 ) - как это работает внутри языка?


0

1

Думал, format - метод класса string. Читаю доку: http://docs.python.org/2/library/string.html

New in version 2.6.

The built-in str and unicode classes provide the ability to do complex variable substitutions and value formatting via the str.format() method described in PEP 3101. The Formatter class in the string module allows you to create and customize your own string formatting behaviors using the same implementation as the built-in format() method.

class string.Formatter
The Formatter class has the following public methods:

format(format_string, *args, **kwargs)
format() is the primary API method. It takes a format string and an arbitrary set of positional and keyword arguments. format() is just a wrapper that calls vformat().

Что значит string.Formatter? Класс, определённый внутри класса string? Каким тогда образом метод format доступен записью str.format(), он же не метод класса string?

Enjoy your python

anonymous
()

Посмотри в сорцах питона как устроено. В чем проблема-то?

anonymous
()

В этом куске доке ВСЁ написано, что конкретно тебе непонятно?

greek_31 ★★
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.