python计算入门_Python入门(二) 基本运算

Python支持如下的基本运算:

1)数学运算:+, -, *, /, %, **, 分别是加,减,乘,除,取余,乘方

2)逻辑运算:and, or, not,分别是逻辑与,逻辑或,逻辑非

3)比较运算符:==, !=,  >, =, <=,

4)位运算符:按位与&, 按位或|, 按位异或^,按位取反~, 左移>>, 右移<<

5)成员运算符:用于判断序列是否存在某值,其中序列包括字符串,tuple, list这三种。

in:如果在指定的序列中找到值,返回True,否则返回False

not in:如果在指定的序列中找不到值,返回True,否则返回False

a = 10

b = 20

list = [1, 2, 3, 4, 5 ];

if ( a in list ):

print "Line 1 - a is available in the given list"

else:

print "Line 1 - a is not available in the given list"

if ( b not in list ):

print "Line 2 - b is not available in the given list"

else:

print "Line 2 - b is available in the given list"

a = 2

if ( a in list ):

print "Line 3 - a is available in the given list"

else:

print "Line 3 - a is not available in the given list"

7) 身份运算符:用于比较两个对象的存储单元

is:判断标识符是不是引用自同一个对象

is not:判断标识符是不是引用自不同对象

a = 20

b = 20

if ( a is b ):

print "Line 1 - a and b have same identity"

else:

print "Line 1 - a and b do not have same identity"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值