Python 官方文档:入门教程 => 点击学习
python是一门动态语言,解释执行,所有错误都是运行时产生的,即使有错误和异常,只要没有被执行到也不会有错,比如调用不存在的方法;类型是隐式的,也即无需变量类型声明;类型是动态,运行时根据变量指向的内容来决定类型,但是Pyth
Operation | Result | Notes |
---|---|---|
x + y | sum of x and y | |
x - y | difference of x and y | |
x * y | product of x and y | |
x / y | quotient of x and y | (1) |
x // y | (floored) quotient of x and y | (4)(5) |
x % y | remainder of x / y | (4) |
-x | x negated | |
+x | x unchanged | |
abs(x) | absolute value or magnitude of x | (3) |
int(x) | x converted to integer | (2) |
long(x) | x converted to long integer | (2) |
float(x) | x converted to floating point | (6) |
complex(re,im) | a complex number with real part re, imaginary part im. im defaults to zero. | |
c.conjugate() | conjugate of the complex number c. (Identity on real numbers) | |
divmod(x, y) | the pair (x // y, x % y) | (3)(4) |
pow(x, y) | x to the power y | (3)(7) |
x ** y | x to the power y | (7) |
Operation | Result | Notes |
---|---|---|
math.trunc(x) | x truncated to Integral | |
round(x[, n]) | x rounded to n digits, rounding ties away from zero. If n is omitted, it defaults to 0. | 四舍五入 |
math.floor(x) | the greatest integral float <= x | |
math.ceil(x) | the least integral float >= x |
Operation | Meaning | Notes |
---|---|---|
< | strictly less than | |
<= | less than or equal | |
> | strictly greater than | |
>= | greater than or equal | |
== | equal | |
!= 或 <> | not equal | (1) |
is | object identity | |
is not | negated object identity |
Operation | Result | Notes |
---|---|---|
x | y | bitwise or of x and y | |
x ^ y | bitwise exclusive or of x andy | |
x & y | bitwise and of x and y | |
x << n | x shifted left by n bits | (1)(2) |
x >> n | x shifted right by n bits | (1)(3) |
~x | the bits of x inverted |
--结束END--
本文标题: Python基本类型
本文链接: https://www.lsjlt.com/news/190219.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0