Note: from
FutureImport Division <---Division operation python2 Imports this module, in addition to the time, the decimal part will also be displayed, Python3 do not need to import
1 "----------operator + 、—、 *,/,%, *--------"
A=9
B=a3
Print (' B=a3-->%d3=%d '% (A, b))
B=a+1
Print (' b=a+1-->%d+1=%d '% (A, b))
B=a-1
Print (' b=a-1-->%d-1=%d '% (A, b))
B=a/2
Print (' b=a/6-->%d/6=%d '% (A, b)) #只取整数部分, if a decimal is to be written as a float type
Print (9/2)
Print (9//2) #只取整数
b=a%2
Print (the remainder of the ' B=A/2--and the remainder of%D/2 = %d '% (a, b))
B=a3
Print (' b=a3-->%d**3=%d '% (A, b)) #次方
Execution effect:
2 "--------comparison operator----------"
‘‘‘
> 大于
= = equals
! = Not equal to
<> not equal to
< less than
= = greater than equals
<= less than or equal to
"'
3 "--------assignment Operation------------'
c=9
Print (' c=%d '%c)
c+=1 #c +=1<=>c=c+1
Print (' c=%d '%c)
c-=2 #c-=2<=>c=c-2
Print (' c=%d '%c)
C =3 #c =3<=>c=c*3
Print (' c=%d '%c)
c/=5 #c/=5 <=>C=C/5
Print (' c=%0.1f '%c) #保留1位小数
d=30
d%=9 #d%=9<=>d=d%9
Print (' d=%d '%d)
E=20
E =3 #e//=3<=>E=E//3
Print (' c=//%d '%e)
f=5
F =2 #f =2<==>f=f**2
Print (' f= %d '%f '
Execution Effect:
4 "---------logical Operation---------' '
#只能返回真 (True) or False (false), no priority, left---> Right execution
a1=10
A2 =20
If a1==10 and a2==20: #and表示并且, all conditions are set up to execute
print (' via 1 ')
if a1<9 or a2==20: #or表示或, one of the conditions can be executed
Print (' via 2 ')
if a1!=11 or a2!=220:
Print (' via 3 ')
if a1==10 or a2>30:
Print (' via 4 ')
If not a1==11: # Not table non, can be understood as not
print (' through 5 ')
Execution effect:
5 "--------member Operation-----------' '
#只能返回真 (True) or False (false)
A= ' ABC '
If ' B ' in A:
Print (' via 6 ')
if not ' d ' in A:
print (' through 7 ')
Perform effect:
Python base 3--operator