Copyright (c) Hyperion Entertainment and contributors.
Difference between revisions of "AmigaOS Manual: Python Functions"
(→bin) |
|||
Line 45: | Line 45: | ||
As [[AmigaOS_Manual:_Pyhon_Functions#repr.28.29|repr()]], return a string containing a printable representation of an object, but escape the non-ASCII characters in the string returned by [[AmigaOS_Manual:_Pyhon_Functions#repr.28.29|repr()]] using \x, \u or \U escapes. This generates a string similar to that returned by [[AmigaOS_Manual:_Pyhon_Functions#repr.28.29|repr()]] in Python 2. |
As [[AmigaOS_Manual:_Pyhon_Functions#repr.28.29|repr()]], return a string containing a printable representation of an object, but escape the non-ASCII characters in the string returned by [[AmigaOS_Manual:_Pyhon_Functions#repr.28.29|repr()]] using \x, \u or \U escapes. This generates a string similar to that returned by [[AmigaOS_Manual:_Pyhon_Functions#repr.28.29|repr()]] in Python 2. |
||
− | == bin == |
+ | == bin() == |
+ | |||
+ | <nowiki>bin(x)</nowiki> |
||
+ | |||
+ | Convert an integer number to a binary string prefixed with “0b”. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer. Some examples: |
||
+ | >>> bin(3) |
||
+ | '0b11' |
||
+ | |||
+ | >>> 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 format() for more information. |
||
+ | |||
== bool == |
== bool == |
||
== breakpoint == |
== breakpoint == |
Revision as of 14:01, 15 July 2018
Contents
- 1 Built-in Functions Reference
- 1.1 __import__
- 1.2 abs()
- 1.3 all()
- 1.4 any()
- 1.5 ascii()
- 1.6 bin()
- 1.7 bool
- 1.8 breakpoint
- 1.9 bytearray
- 1.10 bytes
- 1.11 callable
- 1.12 chr
- 1.13 classmethod
- 1.14 compile
- 1.15 complex
- 1.16 delattr
- 1.17 dict
- 1.18 dir
- 1.19 divmod
- 1.20 enumerate
- 1.21 eval
- 1.22 exec
- 1.23 filter
- 1.24 float
- 1.25 format
- 1.26 frozenset
- 1.27 getattr
- 1.28 globals
- 1.29 hasattr
- 1.30 hash
- 1.31 help
- 1.32 hex
- 1.33 id
- 1.34 input
- 1.35 int
- 1.36 isinstance
- 1.37 issubclass
- 1.38 iter
- 1.39 len
- 1.40 list
- 1.41 locals
- 1.42 map
- 1.43 max
- 1.44 memoryview
- 1.45 min
- 1.46 next
- 1.47 object
- 1.48 oct
- 1.49 open
- 1.50 ord
- 1.51 pow
- 1.52 print
- 1.53 property
- 1.54 range
- 1.55 repr()
- 1.56 reversed
- 1.57 round
- 1.58 set
- 1.59 setattr
- 1.60 slice
- 1.61 sorted
- 1.62 staticmethod
- 1.63 str
- 1.64 sum
- 1.65 super
- 1.66 tuple
- 1.67 type
- 1.68 vars
- 1.69 zip
Built-in Functions Reference
__import__
abs()
abs(number)
Return the absolute value of a number. The argument may be an integer or a floating point number. If the argument is a complex number, its magnitude is returned.
all()
all(iterable)
Return True if all elements of the iterable are true (or if the iterable is empty). Equivalent to:
def all(iterable): for element in iterable: if not element: return False return True
any()
any(iterable)
Return True if any element of the iterable is true. If the iterable is empty, return False. Equivalent to:
def any(iterable): for element in iterable: if element: return True return False
ascii()
ascii(object)
As repr(), return a string containing a printable representation of an object, but escape the non-ASCII characters in the string returned by repr() using \x, \u or \U escapes. This generates a string similar to that returned by repr() in Python 2.
bin()
bin(x)
Convert an integer number to a binary string prefixed with “0b”. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer. Some examples:
>>> bin(3) '0b11'
>>> 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 format() for more information.