zoukankan      html  css  js  c++  java
  • Python学习入门基础教程(learning Python)--3.3.2 Python的关系运算

        如果if的condition不用布尔表达式来做条件判断而采用关系表达式,实际上关系表达式运算的结果要么是True要么是False。下面我们先了解一些有关关系运算符的基础知识,如下表所示。


        做个小程序测试一下。

    def if_check(): 
    	global x
    	x = 100
    	print(" in if_check x = ", x)
    	if x > 1:
    		print(" x greater than 1")
    	if x == 0:
    		print(" x equal to 0")
    	if x < -100:
    		print(" x lowe than -100")
    	if x >= 100:
    		print(" x greater than or equal to 100")
    	if x != 0:
    		print(" x not equal to 0")
    	
    def main():
    	global x
    	print(" in main x = ", x)
    	if_check()
    
    x = 12
    main()

        程序运行结果如下所示。


        从Python程序运行结果来看,当x = 100时,x > 1 x >= 100 和x != 0这三个if语句关系运算结果为真,所以其下的打印语句执行。



  • 相关阅读:
    JSP总结1
    EL总结2-域
    EL总结1
    getRealPath和getContextPath
    mybatis获取参数数值的两个方式
    进程与线程区别与联系
    进程间通信和线程间通信的区别
    STRLEN
    二叉树数据结构和算法
    TYPDEF使用注意部分
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3162856.html
Copyright © 2011-2022 走看看