栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python 数字类型与操作符

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python 数字类型与操作符

python 数字类型与操作符
    • Python 数字类型
      • 1. Booleans
        • 1.1 常见搭配表达符
      • 2. Integers(int)
        • 2.1 常见操作符
      • 3. Floating point
        • 3.1 常见操作符
      • 4. math 模块
      • 5. 比较符
      • 6. 类型转换

Python 数字类型

Python 有4种数组类型:

  • Booleans (布尔)
  • Integers (整数)
  • Floating point (浮点数)
  • Complex (Imaginary numbers) (复数和虚数)
1. Booleans
a = True
b = False
1.1 常见搭配表达符
and, or, not
2. Integers(int)
a = 37
b = -299392993727716627377128481812241231
c = 0x7fa8      # Hexadecimal
d = 0o253       # Octal
e = 0b10001111  # Binary
2.1 常见操作符
x + y      Add
x - y      Subtract
x * y      Multiply
x / y      Divide (produces a float)
x // y     Floor Divide (produces an integer)
x % y      Modulo (remainder)
x ** y     Power
x << n     Bit shift left
x >> n     Bit shift right
x & y      Bit-wise AND
x | y      Bit-wise OR
x ^ y      Bit-wise XOR
~x         Bit-wise NOT
abs(x)     Absolute value
3. Floating point
a = 37.45
b = 4e5 # 4 x 10**5 or 400,000
c = -1.345e-10
3.1 常见操作符

与整数的操作符相比,没有了按位运算。

x + y      Add
x - y      Subtract
x * y      Multiply
x / y      Divide
x // y     Floor Divide
x % y      Modulo
x ** y     Power
abs(x)     Absolute Value
4. math 模块
import math
a = math.sqrt(x)
b = math.sin(x)
c = math.cos(x)
d = math.tan(x)
e = math.log(x)
5. 比较符
x < y      Less than
x <= y     Less than or equal
x > y      Greater than
x >= y     Greater than or equal
x == y     Equal to
x != y     Not equal to
6. 类型转换
a = int(x)    Convert x to integer
b = float(x)  Convert x to float
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/938321.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号