ITPub博客

首页 > IT职业 > IT图书 > python基础3——运算符

python基础3——运算符

IT图书 作者:anleli 时间:2021-09-09 09:21:40 0 删除 编辑

注:     from future import division

1'''----------运算符 + 、—、*、/、%、*--------'''
a=9
b=a
3
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))#只取整数部分,如需小数写成float类型
print(9/2)
print(9//2)#只取整数
b=a%2
print('b=a/2的余数--> %d/2的余数=····%d'%(a,b))
b=a3
print('b=a
3--> %d**3=%d'%(a,b))#次方

2'''--------比较运算符----------'''
'''

> 大于

==     等于
!=    不等于
    不等于
=>     大于等于
'''

3'''--------赋值运算------------'''
c=9
print('c=%d'%c)
c+=1      #c+=1c=c+1
print('c=%d'%c)
c-=2      #c-=2c=c-2
print('c=%d'%c)
c=3      #c=3c=c*3
print('c=%d'%c)
c/=5      #c/=5c=c/5
print('c=%0.1f'%c)#保留1位小数
d=30
d%=9      #d%=9d=d%9
print('d=%d'%d)
e=20
e//=3     #e//=3e=e//3
print('c=//%d'%e)
f=5
f=2     #f=2f=f**2
print('f=%d'%f)



4'''---------逻辑运算---------'''
#只能返回真(True)或假(False),没有优先级,左--->右执行
a1=10
a2=20
if a1==10 and a2==20:   #and表示并且,所有条件都成立才能执行
print('通过1')
if a1print('通过2')
if a1!=11 or a2!=220:
print('通过3')
if a1==10 or a2>30:
print('通过4')
if not a1==11:          #not表非,可以理解为不是
print('通过5')



5'''--------成员运算-----------'''
#只能返回真(True)或假(False)
a='abc'
if 'b' in a:
print('通过6')
if not 'd' in a:
print('通过7')

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2548/viewspace-2802642/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-16

  • 博文量
    93
  • 访问量
    1074