在了解了比较运算符之后编写实例进行验证,在basis目录下新建文件,命名为comparison.py,学习Python比较运算符的操作,在PyCharm中输入代码。
operand_a = 5
operand_b = 5
operand_c = 2
等于号
print("{} == {} ? [{}]".format(operand_a, operand_b, operand_a == operand_b))
print("{} == {} ? [{}]".format(operand_a, operand_c, operand_a == operand_c))
大于号
print("{} > {} ? [{}]".format(operand_a, operand_b, operand_a > operand_b))
print("{} > {} ? [{}]".format(operand_a, operand_c, operand_a > operand_c))
小于号
print("{} < {} ? [{}]".format(operand_a, operand_b, operand_a < operand_b))
print("{} < {} ? [{}]".format(operand_c, operand_a, operand_c < operand_a))
大于等于号
print("{} >= {} ? [{}]".format(operand_a, operand_b, operand_a >= operand_b))
print("{} >= {} ? [{}]".format(operand_c, operand_a, operand_c >= operand_a))
小于等于号
print("{} <= {} ? [{}]".format(operand_a, operand_b, operand_a <= operand_b))
print("{} <= {} ? [{}]".format(operand_a, operand_c, operand_a <= operand_c))
不等于号
print("{} != {} ? [{}]".format(operand_a, operand_b, operand_a != operand_b))
print("{} != {} ? [{}]".format(operand_a, operand_c, operand_a != operand_c))