4.Python基础 运算

根据Vamei前辈的博客练习Python的,Vamei前辈博客地址:

http://www.cnblogs.com/vamei/archive/2012/05/29/2524376.html

Python也和其它语言有加、减、乘、除、大于、小于、大于等于、小于等于、不等于、与、或、非等运算符,请看下面:

>>> print (2.3+2.1)    #加法
4.4
>>> print (2.5+2.6)    #加法
5.1
>>> print (1.9+2.3)    #加法
4.199999999999999
>>> print (2.1-0.3)    #减法
1.8
>>> print (2.3*3.1)    #乘法
7.13
>>> print (4.5/1.5)    #除法
3.0
>>> print (3**2)    #乘方
9
>>> print (9%2)    #取余
1
>>> print (9%3.3)    #取余
2.4000000000000004
>>> 
>>> 
>>> print (5==6)    #等于
False
>>> print (5==5)
True
>>> print (5!=6)    #不等于
True
>>> print (3<3, 3<=3)  #小于,小于等于
False True
>>> print (4>5)    #大于
False
>>> print (4>0)    #大于
True
>>> print (5 in[1, 2, 5])    #5在list里
True
>>> print (3 is int)
False
>>> print (3 is 3)    #is
True
>>> print (3 is 2)
False
>>> print (3 is not 3)    #is not
False
>>> print (True and True, True and False)    #与,and
True False
>>> print (False or False, True or False)    #或,or
False True
>>> print (not True)    #非,not
False
>>> print ((5!=3) and (1==1))
True
>>> print (not -1)
False
>>> print (not False)
True
>>> print (not 0)
True
>>> print (not 1)
False
>>> print (-1==True)
False
>>> print (-1==False)
False
>>> not -1
False
>>> print ("hello" == 'hello')
True
>>> print ("hello" != "hello")
False
>>> print (not "dd")
False
>>> 

posted @ 2015-07-30 18:33  笑面浮屠  阅读(239)  评论(0编辑  收藏  举报