Members
- abs
- all
- any
- bool
- dict
- dir
- enumerate
- fail
- float
- getattr
- hasattr
- hash
- int
- len
- list
- max
- min
- range
- repr
- reversed
- sorted
- str
- tuple
- type
- zip
abs
unknown abs(x)
abs(-2.3) == 2.3
Parameters
Parameter | Description |
---|---|
x
|
int; or float;
required A number (int or float) |
all
bool all(elements)
all(["hello", 3, True]) == True all([-1, 0, 1]) == False
Parameters
Parameter | Description |
---|---|
elements
|
required A string or a collection of elements. |
any
bool any(elements)
any([-1, 0, 1]) == True any([False, 0, ""]) == False
Parameters
Parameter | Description |
---|---|
elements
|
required A string or a collection of elements. |
bool
bool bool(x=False)
False
if the object is None
, False
, an empty string (""
), the number 0
, or an empty collection (e.g. ()
, []
). Otherwise, it returns True
.
Parameters
Parameter | Description |
---|---|
x
|
default is False The variable to convert. |
dict
dict dict(pairs=[], **kwargs)
Parameters
Parameter | Description |
---|---|
pairs
|
default is [] A dict, or an iterable whose elements are each of length 2 (key, value). |
kwargs
|
required Dictionary of additional entries. |
dir
list dir(x)
Parameters
Parameter | Description |
---|---|
x
|
required The object to check. |
enumerate
list enumerate(list, start=0)
enumerate([24, 21, 84]) == [(0, 24), (1, 21), (2, 84)]
Parameters
Parameter | Description |
---|---|
list
|
required input sequence. |
start
|
default is 0 start index. |
fail
None
fail(msg=None, attr=None, sep=" ", *args)
Parameters
Parameter | Description |
---|---|
msg
|
default is None Deprecated: use positional arguments instead. This argument acts like an implicit leading positional argument. |
attr
|
string; or None ;
default is None Deprecated. Causes an optional prefix containing this string to be added to the error message. |
sep
|
default is " " The separator string between the objects, default is space (" "). |
args
|
required A list of values, formatted with debugPrint (which is equivalent to str by default) and joined with sep (defaults to " "), that appear in the error message. |
float
float float(x=unbound)
- If
x
is already a float,float
returns it unchanged. - If
x
is a bool,float
returns 1.0 for True and 0.0 for False. - If
x
is an int,float
returns the nearest finite floating-point value to x, or an error if the magnitude is too large. - If
x
is a string, it must be a valid floating-point literal, or be equal (ignoring case) toNaN
,Inf
, orInfinity
, optionally preceded by a+
or-
sign.
float()
returns 0.0.
Parameters
Parameter | Description |
---|---|
x
|
default is unbound The value to convert. |
getattr
unknown getattr(x, name, default=unbound)
default
(if specified) or raises an error. getattr(x, "foobar")
is equivalent to x.foobar
.getattr(ctx.attr, "myattr") getattr(ctx.attr, "myattr", "mydefault")
Parameters
Parameter | Description |
---|---|
x
|
required The struct whose attribute is accessed. |
name
|
required The name of the struct attribute. |
default
|
default is unbound The default value to return in case the struct doesn't have an attribute of the given name. |
hasattr
bool hasattr(x, name)
x
has an attribute or method of the given name
, otherwise False. Example:hasattr(ctx.attr, "myattr")
Parameters
Parameter | Description |
---|---|
x
|
required The object to check. |
name
|
required The name of the attribute. |
hash
int hash(value)
String.hashCode()
, namely: s[0] * (31^(n-1)) + s[1] * (31^(n-2)) + ... + s[n-1]
Parameters
Parameter | Description |
---|---|
value
|
required String value to hash. |
int
int int(x, base=unbound)
- If
x
is already an int,int
returns it unchanged. - If
x
is a bool,int
returns 1 for True and 0 for False. - If
x
is a string, it must have the format<sign><prefix><digits>
.<sign>
is either"+"
,"-"
, or empty (interpreted as positive).<digits>
are a sequence of digits from 0 up tobase
- 1, where the letters a-z (or equivalently, A-Z) are used as digits for 10-35. In the case wherebase
is 2/8/16,<prefix>
is optional and may be 0b/0o/0x (or equivalently, 0B/0O/0X) respectively; if thebase
is any other value besides these bases or the special value 0, the prefix must be empty. In the case wherebase
is 0, the string is interpreted as an integer literal, in the sense that one of the bases 2/8/10/16 is chosen depending on which prefix if any is used. Ifbase
is 0, no prefix is used, and there is more than one digit, the leading digit cannot be 0; this is to avoid confusion between octal and decimal. The magnitude of the number represented by the string must be within the allowed range for the int type. - If
x
is a float,int
returns the integer value of the float, rounding towards zero. It is an error if x is non-finite (NaN or infinity).
x
is any other type, or if the value is a string not satisfying the above format. Unlike Python's int
function, this function does not allow zero arguments, and does not allow extraneous whitespace for string arguments.Examples:
int("123") == 123 int("-123") == -123 int("+123") == 123 int("FF", 16) == 255 int("0xFF", 16) == 255 int("10", 0) == 10 int("-0x10", 0) == -16 int("-0x10", 0) == -16 int("123.456") == 123
Parameters
Parameter | Description |
---|---|
x
|
required The string to convert. |
base
|
default is unbound The base used to interpret a string value; defaults to 10. Must be between 2 and 36 (inclusive), or 0 to detect the base as if x were an integer literal. This parameter must not be supplied if the value is not a string.
|
len
int len(x)
Parameters
Parameter | Description |
---|---|
x
|
required The value whose length to report. |
list
list list(x=[])
list([1, 2]) == [1, 2] list((2, 3, 2)) == [2, 3, 2] list({5: "a", 2: "b", 4: "c"}) == [5, 2, 4]
Parameters
Parameter | Description |
---|---|
x
|
default is [] The object to convert. |
max
unknown max(key=None, *args)
max(2, 5, 4) == 5 max([5, 6, 3]) == 6 max("two", "three", "four", key = len) =="three" # the longest max([1, -1, -2, 2], key = abs) == -2 # the first encountered with maximal key value
Parameters
Parameter | Description |
---|---|
key
|
callable; or None ;
default is None An optional function applied to each element before comparison. |
args
|
required The elements to be checked. |
min
unknown min(key=None, *args)
min(2, 5, 4) == 2 min([5, 6, 3]) == 3 min("six", "three", "four", key = len) == "six" # the shortest min([2, -2, -1, 1], key = abs) == -1 # the first encountered with minimal key value
Parameters
Parameter | Description |
---|---|
key
|
callable; or None ;
default is None An optional function applied to each element before comparison. |
args
|
required The elements to be checked. |
None
print(sep=" ", *args)
args
as debug output. It will be prefixed with the string "DEBUG"
and the location (file and line number) of this call. The exact way in which the arguments are converted to strings is unspecified and may change at any time. In particular, it may be different from (and more detailed than) the formatting done by str()
and repr()
.Using print
in production code is discouraged due to the spam it creates for users. For deprecations, prefer a hard error using fail()
whenever possible.
Parameters
Parameter | Description |
---|---|
sep
|
default is " " The separator string between the objects, default is space (" "). |
args
|
required The objects to print. |
range
sequence range(start_or_stop, stop_or_none=None, step=1)
start
to stop
, using a step
increment. If a single argument is provided, items will range from 0 to that element.range(4) == [0, 1, 2, 3] range(3, 9, 2) == [3, 5, 7] range(3, 0, -1) == [3, 2, 1]
Parameters
Parameter | Description |
---|---|
start_or_stop
|
required Value of the start element if stop is provided, otherwise value of stop and the actual start is 0 |
stop_or_none
|
int; or None ;
default is None optional index of the first item not to be included in the resulting list; generation of the list stops before stop is reached.
|
step
|
default is 1 The increment (default is 1). It may be negative. |
repr
string repr(x)
repr("ab") == '"ab"'
Parameters
Parameter | Description |
---|---|
x
|
required The object to convert. |
reversed
list reversed(sequence)
reversed([3, 5, 4]) == [4, 5, 3]
Parameters
Parameter | Description |
---|---|
sequence
|
required The iterable sequence (e.g. list) to be reversed. |
sorted
list sorted(iterable, key=None, *, reverse=False)
sorted([3, 5, 4]) == [3, 4, 5] sorted([3, 5, 4], reverse = True) == [5, 4, 3] sorted(["two", "three", "four"], key = len) == ["two", "four", "three"] # sort by length
Parameters
Parameter | Description |
---|---|
iterable
|
required The iterable sequence to sort. |
key
|
callable; or None ;
default is None An optional function applied to each element before comparison. |
reverse
|
default is False Return results in descending order. |
str
string str(x)
str("ab") == "ab" str(8) == "8"
Parameters
Parameter | Description |
---|---|
x
|
required The object to convert. |
tuple
tuple tuple(x=())
tuple([1, 2]) == (1, 2) tuple((2, 3, 2)) == (2, 3, 2) tuple({5: "a", 2: "b", 4: "c"}) == (5, 2, 4)
Parameters
Parameter | Description |
---|---|
x
|
default is () The object to convert. |
type
string type(x)
type(2) == "int" type([1]) == "list" type(struct(a = 2)) == "struct"
if type(x) == type([]): # if x is a list
Parameters
Parameter | Description |
---|---|
x
|
required The object to check type of. |
zip
list zip(*args)
list
of tuple
s, where the i-th tuple contains the i-th element from each of the argument sequences or iterables. The list has the size of the shortest input. With a single iterable argument, it returns a list of 1-tuples. With no arguments, it returns an empty list. Examples:zip() # == [] zip([1, 2]) # == [(1,), (2,)] zip([1, 2], [3, 4]) # == [(1, 3), (2, 4)] zip([1, 2], [3, 4, 5]) # == [(1, 3), (2, 4)]
Parameters
Parameter | Description |
---|---|
args
|
required lists to zip. |