python学习-10 运算符1

1.加+,减-,乘*,除/

例如:

a = 1
b = 2
c = a + b
print(c)

运算结果:

3

Process finished with exit code 0
a = 1
b = 2
c = a - b
print(c)

运算结果:

-1

Process finished with exit code 0
a = 1
b = 2
c = a * b
print(c)

运算结果:

2

Process finished with exit code 0
a = 1
b = 2
c = a / b
print(c)

运算结果:

0.5

Process finished with exit code 0

2.特殊的 幂 **, 取余%,//取商

例如:

a = 1
b = 2
c = a ** b
print(c)

运算结果:

1

Process finished with exit code 0
a = 9
b = 2
c = a % b
print(c)

运算结果:

1

Process finished with exit code 0
a = 9
b = 2
c = a // b
print(c)

运算结果:

4

Process 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')

运行结果:

ok

Process finished with exit code 0

ps:

子字符串:

name = 'abd'        #'abd'  字符串  ; 'a' 字符
#'bd'  子字符串或者叫子序列
if 'ad' in name:     #   如果a在name里
    print('ok')
else:
    print('error')

运行结果:

error

Process finished with exit code 0

not in:

name = 'abd'
if 'a' not in name:
    print('ok')
else:
    print('error')

运行结果:

error

Process finished with exit code 0

 

转载于:https://www.cnblogs.com/liujinjing521/p/11020423.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值