Function Reference
The [] symbol in subsection headings marks optional arguments. You can leave them out if the default value suits you.
The symbol >>> in the examples below marks the user's input, and the line below indicates the result of evaluating this expression.
The # symbol marks comments (explanations) to the code.
General
len(seq)
Returns the length of an array, the number of dictionary keys, or the length of a string.
int(v)
Converts the argument to an integer.
float(v)
Converts the argument to a fractional number.
str(v)
Converts the argument to a string.
pretty(container, [delimiter])
Formats a number, array, or dictionary using delimiter as the element separator.
Arithmetic
round(v, [nd])
Rounds v to nd decimal places. If the second argument is not specified, it rounds up to an integer.
floor(v)
Rounds the argument down to an integer.
ceil(v)
Rounds the argument up to an integer.
abs(v)
Returns the absolute value
min(a, b, ...)
Returns the minimum argument.
max(a, b, ...)
Returns the maximum argument.
rand()
Returns a fractional number in the half-interval [0, 1).
rand(a, b)
Returns an integer in the interval [a, b].
rand(arr)
Returns a random array element.
Working with strings
startswith(container, s)
Checks that the string container starts with the substring s.
endswith(container, s)
Checks that the string container ends with the substring s.
lower(s)
Converts a string to lower case. Convenient for later comparison with another string, case insensitive.
upper(s)
Converts a string to upper case.
strip(s)
Removes extra spaces at the beginning and end of a string.
split(s, [[sep=' ', [max_split=-1]])
Converts a string to an array, splitting it at the specified sep character (default is a space), you can also specify max_split - the maximum number of divisions.
replace(s, old, new, [count=-1])
Replaces the substring old in the string s with the string new. By default (if count is not specified) all occurrences of the substring are replaced.
Regular Expressions
Regular expressions allow you to check if a string matches a specified pattern, or to search for a substring by a pattern in another string. This is a rather complicated, but very powerful mechanism.
You can read more here: https://ru.wikipedia.org/wiki/Regular_expressions
You can test your regular expressions here: https://regex101.com
match(s, pattern, [flags])
Finds a substring in the string s that matches the regular expression pattern. If there is no such substring, None is returned.
Supported flags:
i - case insensitive
m - multiline matching
s - . (dot) matches line breaks
match_groups(s, pattern, [flags])
Finds a substring in the string s that matches the regular expression pattern. If there is no such substring, None is returned.
Unlike match() returns not a substring, but an array of groups. Moreover, the first element of the array is the entire found substring.
Supported flags:
i - case insensitive
m - multiline matching
s - . (dot) matches line breaks
match_all(s, pattern, [flags])
Finds in the string s all substrings matching the regular expression pattern.
Supported flags:
i - case insensitive
m - multiline matching
s - . (dot) matches line breaks
Working with arrays
Operators
Slices
push(arr, v)
Adds the element v to the end of the arr array.
pop(arr, [i])
Removes the element at index i. If i is not specified, then the last element of the array is removed.
insert(arr, i, v)
Inserts the value v in place of i.
remove(arr, v)
Removes the first occurrence of the element with value v.
sorted(arr)
Returns a copy of the array, the values in which are sorted in ascending order.
sorted(arr, key, reversed=False)
Returns a copy of the array in ascending order (or descending if reversed is True). key is a function that returns a value by which to sort.
reversed(arr)
Returns a copy of an array whose values are in reverse order.
enumerate(arr)
Returns an array of (index, value) pairs.
shuffle(arr)
Returns a copy of the array sorted randomly.
index_of(arr, value)
Returns the index of the first array element equal to the specified value. If there is no element with the specified value in the array, None is returned.
join(arr, [sep])
Concatenates the elements of an array into a single string using the sep separator.
sum(arr)
Returns the sum of the array elements.
map(arr, l)
Returns a copy of the array resulting from applying the lambda function l to each of its elements.
filter(arr, l)
Returns a copy of an array whose elements match the filter specified by the l lambda function.
reduce(arr, l)
Combines the elements of an array into a single entity by calling the passed lambda function l on each element. The first argument of the lambda function is the result accumulated at the moment, the second is the next element of the array.
Working with dictionaries
Operators
get(k, [default])
Returns the value given by the key k. If there is no such key in the dictionary, default is returned.
keys(d)
Returns an array of dictionary keys.
values(d)
Returns an array of dictionary values.
map(d, l)
Returns the array resulting from applying the lambda function l to each key-value pair (k, v).
sorted(d, key, reversed=False)
Returns a copy of the dictionary in ascending order (or descending if reversed is True). key is a function that returns a value by which to sort.
Last updated