Functions
abs(x) → {int|float|complex}
Return the absolute value of
x.
For an int input, it returns the non-negative integer equivalent.
For a float input, it returns the positive floating-point number representing its magnitude.
For a complex input, it computes and returns the modulus (the square root of the sum of the
squares of the real and imaginary parts) as a float.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | complex | The number whose absolute value is computed. |
Returns:
the absolute value of
x
- Type
- int | float | complex
arity(f) → {int}
Returns the number of parameters the given function
f expects, excluding the rest parameter.
Parameters:
| Name | Type | Description |
|---|---|---|
|
function | given function |
Returns:
the number of arguments accepted by
f
- Type
- int
breakpoint() → {NoneType}
Evaluates to the
None value with no effect on the program. In the stepper and CSE
machine visualization, breakpoint() additionally marks a step that the breakpoint
navigation can jump to.
Returns:
the
None value
- Type
- NoneType
clear_all_timeout() → {None}
Cancels every
set_timeout callback that has been scheduled but has not yet fired.
Returns:
None
- Type
- None
complex(v, i) → {complex}
Returns a complex number constructed from either zero, one or two arguments.
If no arguments are given, returns
0j. If one argument is given, it is converted to a complex numbe
r and returned.
If two arguments are given, they are interpreted as the real and imaginary parts of a complex number, respective
ly.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | string | bool | complex | If possible, value is converted
to a complex number. If omitted, it defaults to 0j. If a second argument i is given, t
he first argument cannot be a string |
|
int | float | bool | complex | The imaginary part of the complex number. If omitted, it
defaults to 0. |
Returns:
a complex number constructed from the given
value
- Type
- complex
error(*object) → {NoneType}
Prints the provided
*object arguments to the standard output (similar to a simplified
print) and then raises an exception. This function accepts a variable number of arguments,
converts them to their string representations using str(), outputs them (with a
newline) just like what print does, and immediately halts execution by raising an exception.
Parameters:
| Name | Type | Description |
|---|---|---|
|
any | Objects to be printed to the standard output |
Returns:
the
None value
- Type
- NoneType
imag(x) → {float}
Return the imaginary part of a complex number
x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
complex | a complex number |
Returns:
the imaginary part of
x
- Type
- float
input(prompt) → {string}
If the
prompt argument is present, it is written to standard output without a trailing newline.
The function then reads a line from input, converts it to a string (stripping a trailing newline),
and returns that.
Parameters:
| Name | Type | Description |
|---|---|---|
|
string | An optional string that is written to standard output
(without a trailing newline) before input is read. |
Returns:
the input read from the user as a
string, with any trailing newline removed
- Type
- string
is_boolean(x) → {bool}
Returns True if x is a boolean value (True or False), and False otherwise.
Parameters:
| Name | Type | Description |
|---|---|---|
|
any | given value |
Returns:
whether x is a boolean value
- Type
- bool
is_complex(x) → {bool}
Returns True if x is a complex number, and False otherwise.
Parameters:
| Name | Type | Description |
|---|---|---|
|
any | given value |
Returns:
whether x is a complex number
- Type
- bool
is_float(x) → {bool}
Returns True if x is a floating-point number, and False otherwise.
Parameters:
| Name | Type | Description |
|---|---|---|
|
any | given value |
Returns:
whether x is a floating-point number
- Type
- bool
is_function(x) → {bool}
Returns True if x is a function, and False otherwise.
Parameters:
| Name | Type | Description |
|---|---|---|
|
any | given value |
Returns:
whether x is a function
- Type
- bool
is_integer(x) → {bool}
Returns True if x is an integer, and False otherwise.
Parameters:
| Name | Type | Description |
|---|---|---|
|
any | given value |
Returns:
whether x is an integer
- Type
- bool
is_none(x) → {bool}
Returns True if x is the None value, and False otherwise.
Parameters:
| Name | Type | Description |
|---|---|---|
|
any | given value |
Returns:
whether x is the None value
- Type
- bool
is_number(x) → {bool}
Returns True if x is a number, and False otherwise. A number is an integer,
a floating-point number or a complex number; a boolean is not a number.
Parameters:
| Name | Type | Description |
|---|---|---|
|
any | given value |
Returns:
whether x is a number
- Type
- bool
is_string(x) → {bool}
Returns True if x is a string, and False otherwise.
Parameters:
| Name | Type | Description |
|---|---|---|
|
any | given value |
Returns:
whether x is a string
- Type
- bool
len(s) → {int}
Return the length of
s, where s is a list or a string.
Parameters:
| Name | Type | Description |
|---|---|---|
|
string | list | a list or a string whose length is to be computed |
Returns:
the length of
s
- Type
- int
max(arg1, arg2, *args) → {int|float|string}
Returns the largest of the provided values. If multiple items are equal to the maximum,
the first encountered is returned. All values should be mutually comparable.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | string | The first item to compare. |
|
int | float | string | The second item to compare. |
|
int | float | string | Additional items to compare. |
Returns:
the largest of the provided values
- Type
- int | float | string
min(arg1, arg2, *args) → {int|float|string}
Returns the smallest of the provided values. If multiple items are equal to the minimum,
the first encountered is returned. Arguments must be all comparable numbers (int or float) or all strings.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | string | The first item to compare. |
|
int | float | string | The second item to compare. |
|
int | float | string | Additional items to compare. |
Returns:
the smallest of the provided values
- Type
- int | float | string
print(*object) → {NoneType}
A simplified version of the Python built-in
print function.
This function takes any number of parameters *object, converts them to their
string representations using str(), and writes them to the standard
output (sys.stdout), followed by a newline character. See the official Python
documentation for print.
Parameters:
| Name | Type | Description |
|---|---|---|
|
any | object(s) to be printed to the standard output |
Returns:
the
None value
- Type
- NoneType
random_random() → {float}
Return the next random floating-point number in the range
0.0 ≤ X < 1.0.
Returns:
the next random floating-point number in the range
0.0 ≤ X < 1.0
- Type
- float
real(x) → {float}
Return the real part of a complex number
x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
complex | a complex number |
Returns:
the real part of
x
- Type
- float
repr(object) → {string}
Return a
string representation of object that is unambiguous and suitable for debugging.
For many values, this string can be used to reconstruct object
Parameters:
| Name | Type | Description |
|---|---|---|
|
any | The object to be converted to a string. |
Returns:
the unambiguous
string representation of object
- Type
- string
round(number, ndigits) → {float}
Return
number rounded to ndigits precision after the decimal point. If
ndigits is omitted or is None, it returns the nearest integer
to its input.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The value to be rounded. |
|
int | The number of digits to round to after the decimal point. If omitted
or None, the function rounds to the nearest integer. |
Returns:
the number rounded to
ndigits precision
- Type
- float
set_timeout(f, t) → {None}
Schedules
f to be called with no arguments after t milliseconds have
elapsed, without blocking the calling code. f is invoked once, the next time the
scheduled delay elapses.
Parameters:
| Name | Type | Description |
|---|---|---|
|
function | the function to call once t milliseconds have elapsed |
|
int | float | the delay, in milliseconds, before f is called |
Returns:
None
- Type
- None
str(object) → {string}
Return a
string version of object. If object is not provided, returns
the empty string.
Parameters:
| Name | Type | Description |
|---|---|---|
|
any | The object to be converted to a string.
If not provided, an empty string is returned. |
Returns:
the informal
string representation of object
- Type
- string
time_time() → {float}
Return the number of milliseconds elapsed since
January 1, 1970 00:00:00 UTC.
Returns:
current time in milliseconds
- Type
- float