operator.eq() 功能

operator.eq()函数是运算符模块的库函数,用于对两个值执行“等于运算”,如果第一个值等于第二个值,则返回True,否则返回False。

模块:

import operator

语法:

operator.eq(x,y)

Parameter(s):x,y –要比较的值。

返回值:

此方法的返回类型为bool,如果x等于y,则返回True,否则返回False。

范例1:

# Python operator.eq() Function Example

import operator

# 整数

x = 10

y = 20

print("x:",x, ", y:",y)

print("operator.eq(x,y): ", operator.eq(x,y))

print("operator.eq(y,x): ", operator.eq(y,x))

print("operator.eq(x,x): ", operator.eq(x,x))

print("operator.eq(y,y): ", operator.eq(y,y))print()# 弦

x = "Apple"

y = "Banana"

print("x:",x, ", y:",y)

print("operator.eq(x,y): ", operator.eq(x,y))

print("operator.eq(y,x): ", operator.eq(y,x))

print("operator.eq(x,x): ", operator.eq(x,x))

print("operator.eq(y,y): ", operator.eq(y,y))print()# 打印函数的返回类型

print("type((operator.eq(x,y)): ", type(operator.eq(x,y)))

输出:

x: 10 , y: 20operator.eq(x,y):  Falseoperator.eq(y,x):  Falseoperator.eq(x,x):  Trueoperator.eq(y,y):  True

x: Apple , y: Bananaoperator.eq(x,y):  Falseoperator.eq(y,x):  Falseoperator.eq(x,x):  Trueoperator.eq(y,y):  True

type((operator.eq(x,y)):

范例2:

# Python operator.eq() Function Example

import operator

# 输入两个数字

x = int(input("Enter first number : "))

y = int(input("Enter second number: "))

# 打印值

print("x:",x, ", y:",y)

# 比较

if operator.eq(x,y):

print(x, "is equal to", y)

else:

print(x, "is not equal to", y)

输出:

RUN 1:

Enter first number : 10

Enter second number: 10

x: 10 , y: 10

10 is equal to 10

RUN 2:

Enter first number : 10

Enter second number: 20

x: 10 , y: 20

10 is not equal to 20

python operator用法,Python operator.eq()函数与示例相关推荐

  1. python map用法_Python中 map()函数的用法详解

    python map()函数问题 使用map()函数生成一个值D但是检测D的长度时,只能测一次,一次之后D似不知道你的dataSet 是什么数据,是否是从数据库取出来的结果游标, 如果是的 那么dat ...

  2. python画pr曲线_python 画函数曲线示例

    python 画函数曲线示例 如下所示: import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2 * np.pi ...

  3. python search用法,Python-re中search()函数的用法详解(查找ip)

    1.首先来看一下search()和find()的区别 import re s1 = "2221155" #search 字符串第一次出现的位置 print(re.search(&q ...

  4. python grid用法_Python numpy.mgrid函数方法的使用

    numpy.mgrid numpy.mgrid = nd_grid实例,它返回密集的多维"meshgrid". numpy.lib.index_tricks.nd_grid的实例, ...

  5. python冒号用法-python 列表中[ ]中冒号‘:’的作用

    中括号[ ]:用于定义列表或引用列表.数组.字符串及元组中元素位置 list1 = ["physics", "chemistry", 1997, 2000] l ...

  6. python end用法_Python turtle.end_fill方法代码示例

    本文整理汇总了Python中turtle.end_fill方法的典型用法代码示例.如果您正苦于以下问题:Python turtle.end_fill方法的具体用法?Python turtle.end_ ...

  7. python geometry用法_Python geometry.MultiPolygon方法代码示例

    本文整理汇总了Python中shapely.geometry.MultiPolygon方法的典型用法代码示例.如果您正苦于以下问题:Python geometry.MultiPolygon方法的具体用 ...

  8. python turtle用法,python中turtle用法

    50)#程序启动窗口的大小和位置(从左上角的位 置),该窗口的左上角为屏幕的左上角 pythonsize=30 turtle.pensize(pythonsize)#程序中绘制图片的宽度 turtle ...

  9. python boxplot用法,Python使用plt.boxplot() 参数绘制箱线图

    Python 绘制箱线图主要用 matplotlib 库里 pyplot 模块里的 boxplot() 函数. plt.boxplot() 参数详解 plt.pie(x, # 指定要绘制箱线图的数据: ...

  10. python pprint用法,Python中的pprint(漂亮打印机)

    pprint pprint是一个python模块,可以帮助我们简化复杂数据结构的可读性.该pprint也被称为"漂亮打印". 让我们考虑一个例子, dictionary={'coo ...

最新文章

  1. postman设置Cookie上行参数访问接口
  2. Docker知识2:安装docker-desktop
  3. Html中元素的分类
  4. CocoaPods的安装[转载]
  5. 关于modelsim 6.4a遇到的问题
  6. Packet Tracer 通过配置静态路由实现不同网段之间的通信(详细步骤)
  7. java浮点数数转二进制的数吗_深入理解计算机系统(2.7)-二进制小数和IEEE浮点标准 - Java 技术驿站-Java 技术驿站...
  8. 一步一步写算法(之快速排序)
  9. 机器视觉齿轮质量快速检测
  10. DNS 正向查找与反向查找
  11. AndroidStudio 0.2.x 引入多模块Eclipse项目
  12. Android 深入ViewPager补间动画,实现类京东商城首页广告Banner切换效果
  13. android仿今日头条App、多种漂亮加载效果、选择器汇总、记事本App、Kotlin开发等源码...
  14. kaggle数据集下载
  15. 节奏大师服务器不稳定,节奏大师无法登陆的原因及解决方法
  16. matlab机器学习之knn算法实例
  17. PHP图片与文字合成
  18. linux文件实时同步(rsync+inotiy)
  19. 途牛原创|基于EAV模型的运营系统架构实践
  20. Android app内截屏监听

热门文章

  1. 【办公协作软件】万彩办公大师教程丨全能文档转换工具
  2. 玩转pandas取数_下
  3. 学习go语言里Duck typing 概念
  4. android 获取短信中心号码,无法发短信,短信中心号码设置 解决办法!!!
  5. 极坐标弧长积分公式简单理解 极坐标求面积的公式,dθ 弧长积分公式,rd​原理; 极坐标弧积分
  6. Python 黑板客爬虫闯关的第一关
  7. 谢孟媛初级文法28 课地方副词时间副词和程度副词
  8. Creational patterns
  9. STK入门级模拟卫星轨道
  10. 「360企业安全云」上线,免费护航中小微企业数字化建设