python学习-10 运算符1,,1.加+,减-,乘*
python学习-10 运算符1,,1.加+,减-,乘*
1.加+,减-,乘*,除/
例如:
a = 1b = 2c = a + bprint(c)
运算结果:
3Process finished with exit code 0
a = 1b = 2c = a - bprint(c)
运算结果:
-1Process finished with exit code 0
a = 1b = 2c = a * bprint(c)
运算结果:
2Process finished with exit code 0
a = 1b = 2c = a / bprint(c)
运算结果:
0.5Process finished with exit code 0
2.特殊的 幂 **, 取余%,//取商
例如:
a = 1b = 2c = a ** bprint(c)
运算结果:
1Process finished with exit code 0
a = 9b = 2c = a % bprint(c)
运算结果:
1Process finished with exit code 0
a = 9b = 2c = a // bprint(c)
运算结果:
4Process finished with exit code 0
3.in 和 not in 表示判断
判断某个东西是否在**里
例如:
in
name = ‘abd‘ #‘abd‘ 字符串 ; ‘a‘ 字符if ‘a‘ in name: # 如果a在name里 print(‘ok‘)else: print(‘error‘)
运行结果:
okProcess finished with exit code 0
ps:
子字符串:
name = ‘abd‘ #‘abd‘ 字符串 ; ‘a‘ 字符#‘bd‘ 子字符串或者叫子序列if ‘ad‘ in name: # 如果a在name里 print(‘ok‘)else: print(‘error‘)
运行结果:
errorProcess finished with exit code 0
not in:
name = ‘abd‘if ‘a‘ not in name: print(‘ok‘)else: print(‘error‘)
运行结果:
errorProcess finished with exit code 0
python学习-10 运算符1
相关内容
- 使用 resuests 访问 Python 包索引(PyPI)的 JSON API,
- [原创]win7/64位系统+python3.7.2下安装wordcloud库失败之解决
- python 将IP地址转换成打包后的32位格式,,python 2.7
- python json格式转xml格式,,import xml
- python画樱花,,用python画简单
- python,关于这个里边的私有方法(private)、保护方法(
- python3.6---isin,,isin:相当于ex
- 第三章新建与保存【视频】,,
- 从Python到NumPy,细说最接近人类思维的in操作,
- python抓取jenkins slave总数、online数、offline数写道mysql并展
评论关闭