当前位置: 移动技术网 > IT编程>脚本编程>Python > python学习-10 运算符1

python学习-10 运算符1

2019年06月14日  | 移动技术网IT编程  | 我要评论

qimiwang,素衣紫冠,养生堂2015视频全集

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

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网