一.变量
变量:在程序运行过程中,值会发生改变的量常量:在程序运行过程中,值不会发生改变的量 (字面量,直接在代码中出现的数据)无论是变量还是常量,在创建时都会在内存中开辟一个空间,用于保存它们的值。
1.下面我们用一个例子来了解变量:
`age = 20
name = "张三"
address = "yinchuan"
print(age,name,address)`
结果
二、常见的运算符
1.算术运算符: + - * / %(求余) // (整除) **(幂次方)
举例:
num1 = float(input("请输入第一个数:"))
num2 = float(input("请输入第二个数:"))
print(num1,num2,num1+num2)
print(num1,num2,num1-num2)
print(num1,num2,num1*num2)
print(num1,num2,num1/num2)
print(num1,num2,num1//num2)
print(num1,num2,num1**num2)
print(num1,num2,num1%num2)
2.关系运算符:> < >= <= ==(恒等于) !=(不等于)
举例:
num1 = float(input("请输入第一个数:"))
num2 = float(input("请输入第二个数:"))
print(num1>num2)
print(num1<num2)
print(num1>=num2)
print(num1<=num2)
print(num1==num2)
print(num1!=num2)
3.逻辑运算符:and or
举例:
grades = float(input("Enter your grades:"))
if grades > 100 or grades < 0:
print("请输入正确的数字:")
elif grades == 100:
print("满分")
elif grades >= 90:
print("优秀")
elif grades >= 80:
print("良好")
elif grades >= 70:
print("一般")
elif grades >= 60:
print("及格")
elif grades < 60 and grades > 0:
print("不及格")
else:
print("请正确输入成绩:")
4、赋值运算符:= += -+ *= /= //= **=
赋值将等号右边的赋值给左侧的变量
举例:a+=10 <==> a = a+10
5、位运算符: & | ^