From 81bc32ed4aadbdacf5737b211b9158f622a99969 Mon Sep 17 00:00:00 2001 From: Sharan Yalburgi Date: Wed, 28 Jun 2017 22:15:39 +0530 Subject: [PATCH 1/6] Documentation at /Doc/library/functions.rst modified --- Doc/library/functions.rst | 61 ++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 925da5094c62c8..899967cdd40f7c 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -81,9 +81,23 @@ 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. See + also :func:`format` for more information. + + >>> num = 14 + >>> format(num, '#b'), format(num, 'b') + ('0b1110', '1110') + >>> f'{num:#b}', f'{num:b}' + ('0b1110', '1110') .. class:: bool([x]) @@ -635,16 +649,26 @@ 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:`format` for more information. + + >>> num=255 + >>> '%#x' % num, '%x' % num, '%X' % num + ('0xff', 'ff', 'FF') + >>> format(num, '#x'), format(num, 'x'), format(num, 'X') + ('0xff', 'ff', 'FF') + >>> f'{num:#x}', f'{num:x}', f'{num:X}' + ('0xff', 'ff', 'FF') See also :func:`int` for converting a hexadecimal string to an integer using a base of 16. @@ -878,9 +902,26 @@ 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. See also :func:`format` for + more information. + + >>> num = 10 + >>> '%#o' % num, '%o' % num + ('0o12', '12') + >>> format(num, '#o'), format(num, 'o') + ('0o12', '12') + >>> f'{num:#o}', f'{num:o}' + ('0o12', '12') .. index:: From 7af69a3f04d1b8d231b48f069f10b5ecb1ce1fc5 Mon Sep 17 00:00:00 2001 From: Sharan Yalburgi Date: Thu, 29 Jun 2017 02:48:26 +0530 Subject: [PATCH 2/6] Update functions.rst Update functions.rst based on recommendations from haypo. --- Doc/library/functions.rst | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 899967cdd40f7c..81c7f9d51e9efe 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -83,20 +83,22 @@ are always available. They are listed here in alphabetical order. 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: + 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. See - also :func:`format` for more information. + If prefix "0b" is desired or not, you can use either of the following ways. + See also : + func:`format` for more information. - >>> num = 14 - >>> format(num, '#b'), format(num, 'b') + >>> format(14, '#b'), format(14, 'b') ('0b1110', '1110') - >>> f'{num:#b}', f'{num:b}' + >>> f'{14:#b}', f'{14:b}' ('0b1110', '1110') @@ -659,15 +661,17 @@ are always available. They are listed here in alphabetical order. '-0x2a' 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:`format` for more information. + string either with prefix or not, you can use either of the following ways. + See also : + + func:`format` for more information. - >>> num=255 - >>> '%#x' % num, '%x' % num, '%X' % num + + >>> '%#x' % 255, '%x' % 255, '%X' % 255 ('0xff', 'ff', 'FF') - >>> format(num, '#x'), format(num, 'x'), format(num, 'X') + >>> format(255, '#x'), format(255, 'x'), format(255, 'X') ('0xff', 'ff', 'FF') - >>> f'{num:#x}', f'{num:x}', f'{num:X}' + >>> f'{255:#x}', f'{255:x}', f'{255:X}' ('0xff', 'ff', 'FF') See also :func:`int` for converting a hexadecimal string to an From 90b328c57e7ba37673cb6d1962c45c2a70978042 Mon Sep 17 00:00:00 2001 From: Sharan Yalburgi Date: Thu, 29 Jun 2017 02:59:15 +0530 Subject: [PATCH 3/6] Update functions.rst. Original patch by Manvi B Original patch by Manvi B ( manvishab77@gmail.com) --- Doc/library/functions.rst | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 81c7f9d51e9efe..22a99da3679152 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -83,8 +83,8 @@ are always available. They are listed here in alphabetical order. 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. - + to define an :meth:`__index__` method that returns an integer. + Some examples: >>> bin(12) @@ -92,14 +92,15 @@ are always available. They are listed here in alphabetical order. >>> bin(-10) '-0b1010' - If prefix "0b" is desired or not, you can use either of the following ways. - See also : - func:`format` for more information. - + 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]) @@ -661,12 +662,12 @@ are always available. They are listed here in alphabetical order. '-0x2a' 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. + string either with prefix or not, you can use either of the following ways. See also : - + func:`format` for more information. - + >>> '%#x' % 255, '%x' % 255, '%X' % 255 ('0xff', 'ff', 'FF') >>> format(255, '#x'), format(255, 'x'), format(255, 'X') From 6cba98297fe7f3aa5293b53f6fc5d76a1d2cbff7 Mon Sep 17 00:00:00 2001 From: Sharan Yalburgi Date: Thu, 29 Jun 2017 11:39:44 +0530 Subject: [PATCH 4/6] Update functions.rst. Original patch by Manvi B ( manvishab77@gmail.com) --- Doc/library/functions.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 22a99da3679152..3cd4cf529d6ffe 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -93,12 +93,12 @@ are always available. They are listed here in alphabetical order. '-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. @@ -664,7 +664,7 @@ are always available. They are listed here in alphabetical order. 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:`format` for more information. From db3377d83e5b520c08f1dd665209494a772fbaa7 Mon Sep 17 00:00:00 2001 From: Sharan Yalburgi Date: Thu, 29 Jun 2017 13:31:48 +0530 Subject: [PATCH 5/6] Update functions.rst. Original patch by Manvi B ( manvishab77@gmail.com) --- Doc/library/functions.rst | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 3cd4cf529d6ffe..42cf9662d5aa7b 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -99,8 +99,7 @@ are always available. They are listed here in alphabetical order. >>> f'{14:#b}', f'{14:b}' ('0b1110', '1110') - See also : - func:`format` for more information. + See also :func:`format` for more information. .. class:: bool([x]) @@ -663,9 +662,6 @@ are always available. They are listed here in alphabetical order. 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:`format` for more information. >>> '%#x' % 255, '%x' % 255, '%X' % 255 @@ -675,8 +671,9 @@ are always available. They are listed here in alphabetical order. >>> f'{255:#x}', f'{255:x}', f'{255:X}' ('0xff', 'ff', 'FF') - See also :func:`int` for converting a hexadecimal string to an - integer using a base of 16. + See also :func:`format` for more information. + + See also :func:`int` for converting a hexadecimal string to an integer using a base of 16. .. note:: @@ -909,7 +906,9 @@ are always available. They are listed here in alphabetical order. 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: + define an :meth:`__index__` method that returns an integer. + + For example: >>> oct(10) '0o12' @@ -917,8 +916,7 @@ are always available. They are listed here in alphabetical order. '-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. See also :func:`format` for - more information. + or not, you can use either of the following ways. >>> num = 10 >>> '%#o' % num, '%o' % num @@ -928,6 +926,7 @@ are always available. They are listed here in alphabetical order. >>> f'{num:#o}', f'{num:o}' ('0o12', '12') + See also :func:`format` for more information. .. index:: single: file object; open() built-in function From b0140aa43bf5292228f1d6e15fdfcee396267285 Mon Sep 17 00:00:00 2001 From: Sharan Yalburgi Date: Thu, 29 Jun 2017 13:36:55 +0530 Subject: [PATCH 6/6] Update functions.rst. Original patch by Manvi B ( manvishab77@gmail.com) --- Doc/library/functions.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 42cf9662d5aa7b..28d71e7e449e5c 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -906,7 +906,7 @@ are always available. They are listed here in alphabetical order. 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. + define an :meth:`__index__` method that returns an integer. For example: @@ -916,7 +916,7 @@ are always available. They are listed here in alphabetical order. '-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. + or not, you can use either of the following ways. >>> num = 10 >>> '%#o' % num, '%o' % num