eval
输入一个字符串,可以使用eval函数来求值并转换为一个数值
在python解释器中,在一行的结尾处放置一个继续符号(\)来告诉解释器这条语句继续到下一行
sum = 1 + 2 + 3 + 4 + \
5 + 6
sum = 1 + 2 + 3 + 4 + 5 + 6
# = 等号右边的表达式同时赋给左边相对应的变量
x = 1
y = 2
x,y = y,x #swap x with y
#round(x) 返回与x最接近的整数,如果x与两个证书接近程度相同,则返回偶数值
#math模块
import math
x = -2.1
base = 10
print(math.fabs(x)) #把x看做一个浮点数,并返回他的绝对值
print(math.ceil(x)) #x向上取最接近的整数 -2
print(math.floor(x)) #x向下去最接近的整数
print(math.exp(x)) #e**x
y = math.log(x) #返回x的自然对数值
y = math.log(x,base) #返回以某个特殊值为底的x的对数值
y = math.sqrt(x) #x的平方根值
y = math.sin(x) #正弦值 x角度的弧度值
y = math.cos(x)
y = math.asin(x)
y = math.acos(x)
y = math.tan(x)
y = math.atan(x)
y = math.degrees(x) #将x从弧度转成角度
y = math.radians(x) #将x从角度转换弧度
y = math.e
y = math.pi #两个数学常量
#python提供ord(ch)函数来返回字符ch的ASCII码,用chr(code)函数返回code所代表的字符
print(ord("A"))
print(chr(98))
print("He said,\"John's program is easy yo read\"") #\"在一起代表一个字符
print(y,end = '') #不换行打印,中间可以加一些符号
#str可以将一个数字转换成一个字符串
最小化数值错误
在循环条件中使用浮点数可能会导致数值错误
continue退出一次迭代 而break退出整个循环
#一个字符串使可以迭代的
s = "ahjdsjfaks"
for ch in s:
print(ch)