-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-26506: hex() documentation: mention "%x" % int (Original patch by Manvi B) #2479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
81bc32e
Documentation at /Doc/library/functions.rst modified
sharanry 7af69a3
Update functions.rst
sharanry 90b328c
Update functions.rst. Original patch by Manvi B
sharanry 6cba982
Update functions.rst. Original patch by Manvi B ( [email protected])
sharanry db3377d
Update functions.rst. Original patch by Manvi B ( manvishab77@gmail…
sharanry b0140aa
Update functions.rst. Original patch by Manvi B ( manvishab77@gmail…
sharanry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,9 +81,25 @@ are always available. They are listed here in alphabetical order. | |
|
||
.. function:: bin(x) | ||
|
||
Convert an integer number to a binary string. The result is a valid Python | ||
expression. If *x* is not a Python :class:`int` object, it has to define an | ||
:meth:`__index__` method that returns an integer. | ||
Convert an integer number to a binary string prefixed with "0b". The result is | ||
a valid Python expression. If *x* is not a Python :class:`int` object, it has | ||
to define an :meth:`__index__` method that returns an integer. | ||
|
||
Some examples: | ||
|
||
>>> bin(12) | ||
'0b1100' | ||
>>> bin(-10) | ||
'-0b1010' | ||
|
||
If prefix "0b" is desired or not, you can use either of the following ways. | ||
|
||
>>> format(14, '#b'), format(14, 'b') | ||
('0b1110', '1110') | ||
>>> f'{14:#b}', f'{14:b}' | ||
('0b1110', '1110') | ||
|
||
See also :func:`format` for more information. | ||
|
||
|
||
.. class:: bool([x]) | ||
|
@@ -635,19 +651,29 @@ are always available. They are listed here in alphabetical order. | |
|
||
.. function:: hex(x) | ||
|
||
Convert an integer number to a lowercase hexadecimal string | ||
prefixed with "0x", for example: | ||
Convert an integer number to a lowercase hexadecimal string prefixed with "0x". | ||
If x is not a Python :class:`int` object, it has to define an __index__() method | ||
that returns an integer. Some examples: | ||
|
||
>>> hex(255) | ||
'0xff' | ||
>>> hex(-42) | ||
'-0x2a' | ||
|
||
If x is not a Python :class:`int` object, it has to define an __index__() | ||
method that returns an integer. | ||
If you want to convert an integer number to uppercase or lowercase hexadecimal | ||
string either with prefix or not, you can use either of the following ways. | ||
|
||
|
||
See also :func:`int` for converting a hexadecimal string to an | ||
integer using a base of 16. | ||
>>> '%#x' % 255, '%x' % 255, '%X' % 255 | ||
('0xff', 'ff', 'FF') | ||
>>> format(255, '#x'), format(255, 'x'), format(255, 'X') | ||
('0xff', 'ff', 'FF') | ||
>>> f'{255:#x}', f'{255:x}', f'{255:X}' | ||
('0xff', 'ff', 'FF') | ||
|
||
See also :func:`format` for more information. | ||
|
||
See also :func:`int` for converting a hexadecimal string to an integer using a base of 16. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hexadecimal and base of 16 seems redundant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I meant is an integer using base of 16, for eg., int('0xff', 16). If it is redundant, I can remove it. |
||
|
||
.. note:: | ||
|
||
|
@@ -878,10 +904,29 @@ are always available. They are listed here in alphabetical order. | |
|
||
.. function:: oct(x) | ||
|
||
Convert an integer number to an octal string. The result is a valid Python | ||
expression. If *x* is not a Python :class:`int` object, it has to define an | ||
:meth:`__index__` method that returns an integer. | ||
Convert an integer number to an octal string prefixed with "0o". The result is | ||
a valid Python expression. If *x* is not a Python :class:`int` object, it has to | ||
define an :meth:`__index__` method that returns an integer. | ||
|
||
For example: | ||
|
||
>>> oct(10) | ||
'0o12' | ||
>>> oct(-56) | ||
'-0o70' | ||
|
||
If you want to convert an integer number to octal string either with prefix "0o" | ||
or not, you can use either of the following ways. | ||
|
||
>>> num = 10 | ||
>>> '%#o' % num, '%o' % num | ||
('0o12', '12') | ||
>>> format(num, '#o'), format(num, 'o') | ||
('0o12', '12') | ||
>>> f'{num:#o}', f'{num:o}' | ||
('0o12', '12') | ||
|
||
See also :func:`format` for more information. | ||
|
||
.. index:: | ||
single: file object; open() built-in function | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
. . . to an uppercase or lowercase . . .