bool, complex, float, intbytearray, bytes, strdict, frozenset, list, set, tuplememoryview, object, property, range, slice, type
`-=[]โจโฉ\;',./~!@#$%^&*()_+{}|:"<>? ๐๐๐๐๐๐๐โ๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง
ร
โโโรโโ
โยฑโ๊๏นฆโโ โฏ ๐ธ๐นโ๐ป๐ผ๐ฝ๐พโ๐๐๐๐๐โ๐โโโ๐๐๐๐๐๐๐โค๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐
๐๐๐๐๐๐๐๐
โผโฝโพโโโโโ
โโโโโโโ โก โคโฅโฆโงโจโฉโชโซ
โโโโโโ โโโโ
โโ ๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐
๐๐๐๐๐๐๐๐๐๐๐๐๐๐
โโโโ
โฆฐโโโโโโดโต โโโโโโโ โงโจโฉโช
โซโฌโญโฎโฏโฐโฑโฒโณ โฅโฎโฏโฐโฑ โ โฒ โณ โด โ โ สน สบ โต โถ โท
๏น ๏น ๏น ๏น ๏ธน ๏ธบ ๏ธป ๏ธผ ๏ธ ๏ธ ๏ธฟ ๏น ๏ธฝ ๏ธพ ๏น ๏น ๏ธท ๏ธธ โ โ โด โต โ โ โ โก
โโโโโคโฆโฅโงโโโโโโโฒโผโโถโบโปโฒโณ โผโฝโพโฟโโโโโโ
โโ โโโโโโโโโโโโโโโณโฅขโฅฃโฅคโฅฅโฅฆโฅงโฅจโฅฉโฅชโฅซโฅฌโฅญโฅฎโฅฏ
Draft for Information Only
Content
Python Built-in Class Functions โbool() โโParameters โโRemarks โcomplex() โโParameters โโRemarks โfloat() โโParameters โโRemarks โint() โโParameters โโRemarks โSource and Reference
Python Built-in Class Functions
The Python interpreter has some built-in class functions.
bool()
class bool([๐ฅ])
Parameters
bool()to return a bool object, True or False
[๐ฅ]optional, to specify the object to be converted from
Remarks
- The
bool class is a subclass of int
- The possible instances of
bool class are True and False. There is no subclass further.
- If optional ๐ฅ is omitted, then
bool() returns False
- ๐ฅ can be any object.
- Given ๐ฅ is converted using the standard truth testing procedure.
Trueby default, an object is considered true.
Falseclass of object that either a __bool__() method that returns False or a __len__() method that return zero.
constants defined to be false: None and False
zero of any numeric type: 0, 0.0, 0๐, Decimal(0), Fraction(0,1), etc.
empty sequences and collections: '', (), [], {}, set(), range(0), etc
complex()
class complex([real[, imag]])
Parameters
complex()to return a complex number.
[real]optional, to specify the object, a string or number, to be converted from
[imag]optional, but real must be given, to specify the imaginary part of a number
Remarks
- Given
real can be specified as following
stringThe given string of parameter real will be interpreted as a complex number. Therefore, the parameter imag should be omitted. Besides, the string must not contain whitespace around the central + or - operator.
numericThe argument of real can be numeric of any type including complex number
omittedthe default is 0
- The argument of
imag can be numeric of any type including complex number. However the argument can never be a string. If parameter imag is omitted, then the default is zero.
- If both arguments are omitted,
complex() returns 0j.
- The
complex() constructor serves as a numeric conversion like int() and float
- For a general Python object ๐ฅ,
complex(๐ฅ) delegates to ๐ฅ.__complex__(). If __complex__() is not defined then it falls back to __float__(). If __float__() is not defined then it falls back to __index__()
float()
class float([๐ฅ])
Parameters
float()to return a floating point number
[๐ฅ]optional, to specify the object to be converted from
Remarks
- if argument is omitted, floating point number 0.0 is returned.
- if argument is a string, the string should contain a decimal number, optionally preceded by a sgn, and optionally embedded in whitespace. The optional sign may be
+, -. A + has no effect on the value produced. The argument may also be a string representing a NaN, not-a-number, or a positive or negative infinity. The leading and trailing whitespace characters are removed
sign::="+" | "-"
infinity::="infinity" | "inf"
nan::="nan"
numeric_value::=floatnumber | infinity | nan
numeric_string::=[sign] numeric_value
floatnumber is the form of a Python floating-point literal. Case is not significant.
- if the argument is an integer or a floating point number, a floating point number of the same value within the Python's floating point precision is returned. If the argument is outside the range of a Python float, an
OverflowError will be raised
- For a general Python object ๐ฅ, float(๐ฅ) delegates to ๐ฅ.
__float__(). If __float__() is not defined then it falls back to __index__().
int()
class int([๐ฅ])
class int(๐ฅ, base=10)
Parameters
int()to return an integer object
๐ฅoptional, to specify the object to be returned from
base=10to
Remarks
- If no arguments are given,
int() return 0
- If ๐ฅ defines
__int__(), int(๐ฅ) returns ๐ฅ.__int__(). If ๐ฅ defines __index__(), int(๐ฅ) returns ๐ฅ.__index__(). If ๐ฅ defines __trunc__(), int(๐ฅ) returns ๐ฅ.__trunc__(). For floating point numbers, this truncates towards zero.
- If ๐ฅ is not a number or if argument
base is given, then ๐ฅ must be a string, bytes, or bytearray instance representing an integer literal in radix base. Optionally, the literal can be preceded by +, or -, with no space in between and surrounded by whitespace.
- A base-๐ literal consists of the digits 0 to ๐-1, with ๐ to ๐ง (or ๐ด to ๐) having values 10 to 35. The default
base is 10. The allowed values are 0, and 2 to 36. Base-2, base-8, and base-16 literals can be optionally prefixed with 0b/0B, 0o/0O, or 0x/0X, as with integer literals in code. Base 0 means to interpret exactly as a code literal, so that the actual base is 2, 8, 10, 16, and so that int('010',0) is not legal, while int('010') is, as well as int('010',8)
Source and Reference
ยฉsideway
ID: 200601902 Last Updated: 6/19/2020 Revision: 0
|
 |