mult¶
Syntax¶
Parameters¶
x- An expression that evaluates to a number or a list.
y- An expression that evaluates to a number or a list.
Returns¶
The result is a single value if both arguments are single-valued expressions; otherwise the result is a list.
Description¶
If x and y are single-valued expressions, the action returns the product of
the two given values.
If one the arguments is a single-valued expression and the other is a list-expression, then the action returns a list of values consisting of the product of the single value and each item in the list.
If both arguments are list-expressions, then the action returns a list of values consisting of the product of each value in the list multiplied by the value at the same index of the corresponding list. In this case, the lists must have the same number of items.
This action is the prefix notation for the expression x * y.
If both arguments are list-expressions, a run-time error occurs if the lists have different lengths.
Examples¶
z = mult(10, 2) # z = 20
z = 10 * 2 # z = 20
my_list = list(1, 2, 3)
new_list = mult(my_list, 4) # new_list = list(4, 8, 12)
new_list = my_list * 4 # new_list = list(4, 8, 12)
new_list = 4 * my_list # new_list = list(4, 8, 12)
new_list = my_list * my_list # new_list = list(1, 4, 9)