开发者学堂课程【Python 语言基础 1 :语法入门:算数运算符】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/599/detail/8674
算数运算符
内容简介:
1. 运算符介绍及分类
2. 算数运算符的详细介绍
运算符介绍及分类:
#运算符(操作符)
运算符可以对一个值或多个值进行运算或各种操作比如+、-、=都属于运算符
#运算符的分类:
1.算术运算符
2.赋值运算符
3.比较运算符(关系运算符)
4.逻辑运算符
5.条件运算符(三元运算符)
算数运算符的详细介绍:
#+加法运算符(如果是两个字符串之间进行加法运算,则会进行拼串操作)
#-减法运算符
#*乘法运算符(如果将字符串和数字相乘,则会对字符串进行复制操作,将字符串重复指定次数)。
#/除法运算符,运算时结果总会返回一个浮点类型
#//整除,只会保留计算后的整数位,总会返回一个整型
#**幂运算,求一个值的几次幂I
#%取模,两个数相乘的余数
演示例子:
加法演示:
a=10+5#计算
a='hello'+''+'world'#拼串
print(”a=”,a)
加法结果:
a =hello world
减法演示:
a=10+5#计算
a='hello'+''+'world'#拼串
a =10-5#计算
print(”a=”,a)
减法结果:
a=5
乘法演示:
a=10+5#计算
a='hello'+''+'world'#拼串
a =10-5#计算
a=5 -True
a=a-2 #用变量a的值减去2,然后在赋值给a
# a=‘hello’-‘h’ TypeError
a=5*5
print(”a=”,a)
乘法结果:
a =25
除法演示;
a=10+5#计算
a='hello'+''+'world'#拼串
a =10-5#计算
a=5 -True
a=a-2 #用变量a的值减去2,然后在赋值给a
# a=‘hello’-‘h’ TypeError
a=5*5
a = 10/5
print(”a=”,a)
除法结果:
a=2.0
整除演示:
a=10+5#计算
a='hello'+''+'world'#拼串
a =10-5#计算
a=5 -True
a=a-2 #用变量a的值减去2,然后在赋值给a
# a=‘hello’-‘h’ TypeError
a=5*5
a = 10/5
a=5/2
#a=5/0 ZeroDivisionError :division by zero
print(”a=”,a)
整除结果:
a=2
幂运算演示:
a=5-True
a=a-2 #用变量a的值减去2,然后再赋值给a
#a='hello'-'h 'TypeError
a=5*5
a=10/5
a=5/2
#a=5/θ ZeroDivisionError :division by zero
a=10/3
a=10//3
a=5//2
a=2**2
a=10**5
print(“a=”,a)
幂运算结果:
a= 100000
取余演示:
a=10+5#计算
a='hello'+''+'world'#拼串
a=10-5#计算
a=5-True
a=a-2 #用变量a的值减去2,然后再赋值给a
#a='hello'-'h 'TypeError
a=5*5
a=10/5
a=5/2
#a=5/θ ZeroDivisionError :division by zero
a=10/3
a=10//3
a=5//2
a=2**2
a=10**5
a=16**0.5#求16 的平方根
a=10%5#0
print(“a=”,a)
取余结果:
a=0