python 运算符

成员运算
in 包含
# name = "伴燕儿飞"
# if "燕儿" in name:
#     print("在里面字符串里面")
# else:
#     print("不在字符串里面")

not in 不包含
# name = "伴燕儿飞"
# if "桥" not in name:
#     print("不在字符串里面")
# else:
#     print("在字符串里面")

获取的是布尔值:
True , False
开头字母为大写

 

逻辑运算符
'and从前往后执行,前面为假都为假. or从前往后执行,前面为真后面都为真'
user = "root"
pwd = "12345"
v = user == "root" and pwd == "12345" and 1==1 or 1==2 and user=="roo" and pwd=="1234"
print(v)

获取的是布尔值:
True , False
开头字母为大写

 

比较运算符

1 == 1
a != b
1 <= 2
1 >= 1
2 < 2
3 > 3

获取的是布尔值:
True , False
开头字母为大写

 

 

赋值运算

等价于
count = count + 1
count += 1

等价于
count = count - 1
count  -= 1

count = count / 1
..
count = count * 1
..
count = count % 1
..
count = count // 1

 


n = "qiao" n_2 = "yan" s = "my name is %s 520" %n ,"%s"%n_2 print(s)

'''字符串中有一个%s,他的含义这里将被替换成一个新的字符串,
用作替换的内容放在字符串后面的%后面,就是那个n
('my name is qiao 520', 'yan')
'''

 

 
print('两数之和为 %.3f' %(float(input('输入第一个数字:'))+float(input('输入第二个数字:'))))
#%.3f,代表保留3位小数

 


posted @ 2018-03-19 05:38  快闪开,我要起飞了  阅读(161)  评论(0编辑  收藏  举报