Python运算符

一、运算符

  以下为python运算符  

运算符描述
[] [:] 下标,切片
** 指数
~ + - 按位取反, 正负号
* / % // 乘,除,模,整除
+ - 加,减
>> << 右移,左移
& 按位与
^ | 按位异或,按位或
<= < > >= 小于等于,小于,大于,大于等于
== != 等于,不等于
is is not 身份运算符
in not in 成员运算符
not or and 逻辑运算符
= += -= *= /= %= //= **= &= ` = ^= >>= <<=`

练习

1:温度转化   

"""
将华氏温度转换为摄氏温度
F = 1.8C + 32
"""

f = int(input('请输入华氏温度:'))
c = (f - 32)/1.8
print(c)

2:输入年份判断是不是闰年。

"""
输入年份 如果是闰年输出True 否则输出False

"""

year = int(input('请输入年份:'))
if (year % 4 == 0 and year % 100 != 0 or
           year % 400 == 0):
     print(True)
else:
     print(False)

3:水仙花数

"""
输入一个数判断是不是水仙花数

"""

num = int(input('请输入一个三位数:'))
a = num%10
b = int(num/10%10)
c = int(num/100)
if a**3 + b**3 + c**3 == num:
     print(True)
else:
     print(False)

 

posted @ 2019-09-07 11:29  zcb_bai  阅读(98)  评论(0编辑  收藏  举报