Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c611db49
Commit
c611db49
authored
Feb 19, 2019
by
Stéphane Wirtel
Committed by
Miss Islington (bot)
Feb 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.7] bpo-35126: Fix a mistake in FAQ about converting number to string (GH-11911)
https://bugs.python.org/issue35126
parent
d5409eb6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
3 deletions
+23
-3
Doc/faq/programming.rst
Doc/faq/programming.rst
+21
-3
Misc/NEWS.d/next/Documentation/2019-02-18-10-01-07.bpo-35126.LWwl8X.rst
...xt/Documentation/2019-02-18-10-01-07.bpo-35126.LWwl8X.rst
+2
-0
No files found.
Doc/faq/programming.rst
View file @
c611db49
...
@@ -997,9 +997,27 @@ To convert, e.g., the number 144 to the string '144', use the built-in type
...
@@ -997,9 +997,27 @@ To convert, e.g., the number 144 to the string '144', use the built-in type
constructor :func:`str`. If you want a hexadecimal or octal representation, use
constructor :func:`str`. If you want a hexadecimal or octal representation, use
the built-in functions :func:`hex` or :func:`oct`. For fancy formatting, see
the built-in functions :func:`hex` or :func:`oct`. For fancy formatting, see
the :ref:`formatstrings` section, e.g. ``"{:04d}".format(144)`` yields
the :ref:`formatstrings` section, e.g. ``"{:04d}".format(144)`` yields
``'0144'`` and ``"{:.3f}".format(1/3)`` yields ``'0.333'``. You may also use
``'0144'`` and ``"{:.3f}".format(1.0/3.0)`` yields ``'0.333'``. In Python 2, the
:ref:`the % operator <string-formatting>` on strings. See the library reference
division (/) operator returns the floor of the mathematical result of division
manual for details.
if the arguments are ints or longs, but it returns a reasonable approximation of
the division result if the arguments are floats or complex::
>>> print('{:.3f}'.format(1/3))
0.000
>>> print('{:.3f}'.format(1.0/3))
0.333
In Python 3, the default behaviour of the division operator (see :pep:`238`) has
been changed but you can have the same behaviour in Python 2 if you import
``division`` from :mod:`__future__`::
>>> from __future__ import division
>>> print('{:.3f}'.format(1/3))
0.333
You may also use :ref:`the % operator <string-formatting>` on strings. See the
library reference manual for details.
How do I modify a string in place?
How do I modify a string in place?
...
...
Misc/NEWS.d/next/Documentation/2019-02-18-10-01-07.bpo-35126.LWwl8X.rst
0 → 100644
View file @
c611db49
Improve the examples in the "How do I convert a number to string?" question
of the "Programming" section of the FAQ. Contributed by Stéphane Wirtel.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment