python运算符
来源:互联网 发布:福建 知乎 编辑:程序博客网 时间:2024/05/16 00:59
python运算符与表达式
1、什么是运算符
在python中,有的时候我们需要对一个或多个数字或者一个或者多个字符串进行运算操作,比如让字符串重复的*也是一种运算符,2+3中的"+"也是运算符。
2、运算符有哪些
在python中我们常见的运算符有:+、-、*、/、**、<、>、=、//、%、&、|、^、~、
>>、<<、<=、>=、==、not、and、or。
3、运算符的使用方法
#"+":两个对象相加#两个数字相加a=7+8print a#两个字符串相加b="GOOD"+" JOB!"print b#"-":取一个数的相反数或者实现两个数字相见a=-7print ab=-(-8)print bc=19-1print c#"*":两个数相乘或者字符串重复a=4*7print ab="hello"*7print b#"/":两个数字相除a=7/2print ab=7.0/2c=7/2.0print bprint c#"求幂运算"a=2**3 #相当于2的3次幂print a#"<":小于符号,返回一个bool值a=3<7print ab=3<3print b#"!=":不等于符号,同样返回一个bool值a=2!=3print ab=2!=2print b#"//"除法运算,然后返回其商部分,舍去余数a=10//3print a#"%":取模运算a=10%3print ab=10%1print ba=10//3b=10%3c=3*a+bprint c#"&":按位与运算,所谓的按位的与运算是指一个数字转化为二进制,# 然后这些二进制的数按位来进行与运算a=7&18print a#"|":按位或运算,同样我们要将数字转化为二进制之后按位进行或运算a=7|18print a#"^"按位异或a=7^18print a#"~":按位翻转: ~x=-(x+1)a=~18print a#"<<":左移a=18<<1print ab=3<<3print b#">>"右移a=18>>1print ab=18>>2print b#"<="和">="a=5<=5print ab=6>=5print b#"=="比较两个对象是否相等a=12==13print ab="hello"=="hello"print b#not:逻辑非a=Trueb=not aprint b#and:逻辑与print True and True#or:逻辑或print True or False
阅读全文
0 0
- Python 运算符
- Python运算符重载
- Python 的运算符
- python运算符优先级
- python运算符
- python 运算符详解
- Python运算符重载
- Python运算符重载
- python 运算符
- python-DAY2-运算符
- Python 切片运算符
- 运算符-python
- Python中运算符
- python-运算符
- python的运算符
- Python运算符重载
- Python 运算符
- Python运算符重载
- 工作日志的坑位
- 自己编写Android Studio插件 别停留在用的程度了
- jsp中使用EL表达式,出现Uncaught SyntaxError: Unexpected number错误
- pandas学习笔记5—DataFrame数据筛选loc,iloc,ix,at,iat
- PHP操作MongoDB
- python运算符
- C++之函数对象(Function Object) & for_each
- MPC-BE [Media Player Classic
- RSA密码
- Pod 私有化本地仓库
- 埃式筛法模板及其改进
- LeetCode 学习 LinkedList 专项(1)—— Delete Node in a Linked List
- Maven的存储库问题
- 鲁棒性