(创建页面,内容为“本页面为使用 Python 数学表达式的模版(如calc模版)提供帮助。 ==运算符== ===算数运算符=== {| class="wikitable sortable" ! 运算符 !! 意义 !! 示例 |- | <code>+</code> || 和 || <pre>1 + 2 = 3</pre> |- | <code>-</code> || 差 || <pre>3 - 1 = 2</pre> |- | <code>*</code> || 积 || <pre>2 * 3 = 6</pre> |- | <code>**</code> || 幂 || <pre>2 ** 3 = 8</pre> |- | <code>/</code> || 商 || <pre>6 / 3 = 2</pre> |- | <code>//</code…”) |
(→代数函数) |
||
第92行: | 第92行: | ||
| <code>fmod(x, y)</code> || 取模 || <pre>fmod(5, 2) = 1.0</pre> | | <code>fmod(x, y)</code> || 取模 || <pre>fmod(5, 2) = 1.0</pre> | ||
|- | |- | ||
| <code> | | <code>pow(x, y)</code> || 开平方 || <pre>pow(4) = 2.0</pre> | ||
|- | |- | ||
| <code></code> || || <pre></pre> | | <code>sqrt(x)</code> || 开平方 || <pre>sqrt(4) = 2.0</pre> | ||
|- | |- | ||
| <code></code> || || <pre></pre> | | <code>exp(x)</code> || ''e'' 的 x 次幂 || <pre>exp(2) = 7.38905609893065</pre> | ||
|- | |- | ||
| <code></code> || || <pre></pre> | | <code>log(x[, y])</code> || 对数<br>(默认为自然对数) || <pre>log(e) = 1.0</pre><br><pre>log(4, 2) = 2.0</pre> | ||
|- | |- | ||
| <code></code> || || <pre></pre> | | <code>log2(x)</code> || 以 2 为底的对数 || <pre>log2(4) = 2.0</pre> | ||
|- | |||
| <code>log10(x)</code> || 以 10 为底的对数 || <pre>log10(100) = 2.0</pre> | |||
|- | |- | ||
| <code></code> || || <pre></pre> | | <code></code> || || <pre></pre> |
2023年1月20日 (五) 06:41的版本
本页面为使用 Python 数学表达式的模版(如calc模版)提供帮助。
运算符
算数运算符
运算符 | 意义 | 示例 |
---|---|---|
+ |
和 | 1 + 2 = 3 |
- |
差 | 3 - 1 = 2 |
* |
积 | 2 * 3 = 6 |
** |
幂 | 2 ** 3 = 8 |
/ |
商 | 6 / 3 = 2 |
// |
取整除 | 7 // 4 = 1 |
% |
取模 | 5 % 2 = 1 |
比较运算符
运算符 | 意义 | 示例 |
---|---|---|
== |
等于 | 1 == 1 = True |
!= |
不等于 | 1 != 1 = False |
< |
小于 | 1 < 2 = True |
> |
大于 | 2 > 1 = True |
<= |
小于等于 | 1 <= 2 = True |
>= |
大于等于 | 2 >= 1 = True |
按位运算符
运算符 | 意义 | 示例 | 二进制 |
---|---|---|---|
& |
按位与 | 10 & 12 = 8 |
1010 & 1100 = 1000 |
按位或 | 10 | 12 = 14 |
1010 | 1100 = 1110 | |
^ |
按位异或 | 10 ^ 12 = 6 |
1010 ^ 1100 = 0110 |
~ |
按位取反 | ~ 12 = - 13 |
~ 1100 = 0011 |
>> |
右移 | 12 >> 2 = 3 |
001100 >> 2 = 000011 |
<< |
左移 | 12 << 2 = 48 |
001100 << 2 = 110000 |
逻辑运算符
运算符 | 意义 | 示例 |
---|---|---|
and |
布尔与 | True and False = False |
or |
布尔或 | True or False = True |
not |
布尔非 | not True = False |
函数
数学函数
本页面列举了常见函数。
所有数学函数,参见 https://docs.python.org/zh-cn/3/library/math.html
代数函数
函数 | 意义 | 示例 |
---|---|---|
ceil(x) |
向上取整 | ceil(3.14) = 4 |
floor(x) |
向下取整 | floor(3.14) = 3 |
gcd(x, y, ...) |
最大公约数 | gcd(4, 14) = 2 |
lcm(x, y, ...) |
最小公倍数 | lcm(4, 14) = 28 |
perm(n, k) |
排列 | perm(4, 2) = 12 |
comb(n, k) |
组合 | comb(4, 2) = 6 |
fabs(x) |
绝对值 | fabs(-1) = 1.0 |
fmod(x, y) |
取模 | fmod(5, 2) = 1.0 |
pow(x, y) |
开平方 | pow(4) = 2.0 |
sqrt(x) |
开平方 | sqrt(4) = 2.0 |
exp(x) |
e 的 x 次幂 | exp(2) = 7.38905609893065 |
log(x[, y]) |
对数 (默认为自然对数) |
log(e) = 1.0 log(4, 2) = 2.0 |
log2(x) |
以 2 为底的对数 | log2(4) = 2.0 |
log10(x) |
以 10 为底的对数 | log10(100) = 2.0 |
|
||
|
||
|
||
|
||
|
三角函数
函数 | 意义 | 示例 |
---|---|---|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|