#加减乘除运算顺序1 exponentiation 指数幂
2 multiplication or division 乘除法
3 addition or substraction 加减法
x=10+2*2**3print(x)
打印:26
#四舍五入函数round()
x=2.9print(round(x))
#绝对值函数abs()
x=-2.9print(abs(x))
#导入模块并使用模块中的一些函数import math #导入math moduleprint(math.ceil(2.9))#向上进位 打印:3print(math.floor(2.9))#向下进位 打印:2#更多math module使用看(搜索python 3 math module)# https://docs.python.org/3/library/math.html
#if-else的双分支
is_hot=Trueif is_hot:print("It's a hot day.")else:print("It's a cold day.")print("Enjoy your day")
#if-else的多分支
is_hot=False
is_cold=Trueif is_hot:print("It's a hot day.")elif is_cold:print("It's a cold day.")else:print("It's not hot and not cold day.")print("Enjoy your day")
#逻辑运算符 and 的使用
has_high_income=True
has_good_credit=Trueif has_high_income and has_good_credit:print("Eligable for loan.")
#逻辑运算符 or 的使用
has_high_income=True
has_good_credit=Falseif has_high_income or has_good_credit:print("Eligable for loan.")
#逻辑运算符 not 的使用
has_good_credit =True
has_criminal_record =Falseif has_high_income andnot has_criminal_record:print("Eligable for loan.")
#比较运算符
temperature=30if temperature >30:print("It's a hot day.")else:print("It's not a hot day.")if temperature ==30:#和赋值运算符=不一样print("It's a hot day.")else:print("It's not a hot day.")