Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 32657fb

Browse files
committed
Merge with 3.2.
2 parents 6cb2b92 + 0def5c6 commit 32657fb

1 file changed

Lines changed: 19 additions & 20 deletions

File tree

Doc/tutorial/inputoutput.rst

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ which can be read by the interpreter (or will force a :exc:`SyntaxError` if
4040
there is not equivalent syntax). For objects which don't have a particular
4141
representation for human consumption, :func:`str` will return the same value as
4242
:func:`repr`. Many values, such as numbers or structures like lists and
43-
dictionaries, have the same representation using either function. Strings and
44-
floating point numbers, in particular, have two distinct representations.
43+
dictionaries, have the same representation using either function. Strings, in
44+
particular, have two distinct representations.
4545

4646
Some examples::
4747

@@ -50,9 +50,7 @@ Some examples::
5050
'Hello, world.'
5151
>>> repr(s)
5252
"'Hello, world.'"
53-
>>> str(1.0/7.0)
54-
'0.142857142857'
55-
>>> repr(1.0/7.0)
53+
>>> str(1/7)
5654
'0.14285714285714285'
5755
>>> x = 10 * 3.25
5856
>>> y = 200 * 200
@@ -103,17 +101,18 @@ Here are two ways to write a table of squares and cubes::
103101
(Note that in the first example, one space between each column was added by the
104102
way :func:`print` works: it always adds spaces between its arguments.)
105103

106-
This example demonstrates the :meth:`rjust` method of string objects, which
107-
right-justifies a string in a field of a given width by padding it with spaces
108-
on the left. There are similar methods :meth:`ljust` and :meth:`center`. These
109-
methods do not write anything, they just return a new string. If the input
110-
string is too long, they don't truncate it, but return it unchanged; this will
111-
mess up your column lay-out but that's usually better than the alternative,
112-
which would be lying about a value. (If you really want truncation you can
113-
always add a slice operation, as in ``x.ljust(n)[:n]``.)
104+
This example demonstrates the :meth:`str.rjust` method of string
105+
objects, which right-justifies a string in a field of a given width by padding
106+
it with spaces on the left. There are similar methods :meth:`str.ljust` and
107+
:meth:`str.center`. These methods do not write anything, they just return a
108+
new string. If the input string is too long, they don't truncate it, but
109+
return it unchanged; this will mess up your column lay-out but that's usually
110+
better than the alternative, which would be lying about a value. (If you
111+
really want truncation you can always add a slice operation, as in
112+
``x.ljust(n)[:n]``.)
114113

115-
There is another method, :meth:`zfill`, which pads a numeric string on the left
116-
with zeros. It understands about plus and minus signs::
114+
There is another method, :meth:`str.zfill`, which pads a numeric string on the
115+
left with zeros. It understands about plus and minus signs::
117116

118117
>>> '12'.zfill(5)
119118
'00012'
@@ -128,16 +127,16 @@ Basic usage of the :meth:`str.format` method looks like this::
128127
We are the knights who say "Ni!"
129128

130129
The brackets and characters within them (called format fields) are replaced with
131-
the objects passed into the :meth:`~str.format` method. A number in the
130+
the objects passed into the :meth:`str.format` method. A number in the
132131
brackets can be used to refer to the position of the object passed into the
133-
:meth:`~str.format` method. ::
132+
:meth:`str.format` method. ::
134133

135134
>>> print('{0} and {1}'.format('spam', 'eggs'))
136135
spam and eggs
137136
>>> print('{1} and {0}'.format('spam', 'eggs'))
138137
eggs and spam
139138

140-
If keyword arguments are used in the :meth:`~str.format` method, their values
139+
If keyword arguments are used in the :meth:`str.format` method, their values
141140
are referred to by using the name of the argument. ::
142141

143142
>>> print('This {food} is {adjective}.'.format(
@@ -195,8 +194,8 @@ notation. ::
195194
>>> print('Jack: {Jack:d}; Sjoerd: {Sjoerd:d}; Dcab: {Dcab:d}'.format(**table))
196195
Jack: 4098; Sjoerd: 4127; Dcab: 8637678
197196

198-
This is particularly useful in combination with the new built-in :func:`vars`
199-
function, which returns a dictionary containing all local variables.
197+
This is particularly useful in combination with the built-in function
198+
:func:`vars`, which returns a dictionary containing all local variables.
200199

201200
For a complete overview of string formatting with :meth:`str.format`, see
202201
:ref:`formatstrings`.

0 commit comments

Comments
 (0)