#number 之间的相互转换
#int <=> float
var1 = 1;print(type(var1)) #
res1=float(var1)print(res1) #1.0
print(type(res1)) #
res2=int(res1)print(res2) #1
print(type(res2)) #
#int or float <=> String
var = 1res=str(var)print(type(res)) #
res=float(res)print(type(res)) #
#math 使用
importmath
var=math.piprint(var) #3.141592653589793...
res= math.radians(180)#将角度值转换乘弧度值3.141592653589793 即180度 对应 math.pi
print(res) #3.141592653589793...
res= math.degrees(math.pi) #将弧度转换成角度
print(res) #180.0
res= math.pow(1,2) #等价于x 的 y 次方
print(res) #1.0
print(type(res)) #
res= math.ceil(2.3) #ceil 天花板取值,往上取
print(res) #3
res= math.floor(2.3) #floor 往下取值
print(res) #2
#字符串 => 字典 也可以使用json
var= "{'a':20,'b':40}"
print(type(var)) #
res =eval(var)print(res) #{'a': 20, 'b': 40}
print(type(res)) #
#字典=> 字典字符串 也可以使用json
var = {'a':20,'b':40}
res=str(var)print(type(res)) #
print(res) #{'a': 20, 'b': 40}
#字符串 => 列表 指定分割符号就行
#列表 => 字符串
var = [ 'a','b','c','d'] #要求列表里面都是str类型
res = '-'.join(var)print(res) #a-b-c-d
print(type(res)) #
#列表 => 字典
lst1 = ['k1','k2','k3']
lst2= [1,2]
rest= zip(lst1,lst2) #拉锁函数
print(res)#
print(type(rest)) #
res =dict(rest)print(res) #{'k2': 2, 'k1': 1}
print(type(res)) #