# python 逻辑运算符 #数字运算符 # + - * / % #关系运算符 # == != < > >= <= #负值运算符 # = += -= c -= a c=c-a #逻辑运算符 # and or not ! # 地板除 // # python数据类型 # 赋值时不需要声明变量类型,简单明了 # 整型 int # a = 10 # B = -20 # int(3.5) # 布尔类型bool # B = Ture # b = False # # java c 都需要先声明,在实例化 # int a; a = 10; # a = 10 b = "hello world" c = 11.11 x = 11.81 d = True print(type(a)) print(type(b)) print(type(c)) print(type(x)) print(type(d)) print(int(c)) # 不存在四舍五入 ,直接去掉后面的 print(int(x)) # 不存在四舍五入 ,直接去掉后面的 # 执行结果 # <type 'int'> # <type 'str'> # <type 'float'> # <type 'float'> # <type 'bool'> # 11 # 11 # 浮点型 float # round(float,ngigits) # float 代表数字 # ngigits 代表精度 # 四舍六入 # e = 11.951 f = 11.955 g = 11.958 print(round(e,2)) print(round(f,2)) print(round(g,2)) # 11.95 # 11.96 # 11.96 # π
转载于:https://my.oschina.net/u/3824134/blog/1790172