Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.2数值类型 #10

Open
request101 opened this issue Jun 3, 2019 · 0 comments
Open

1.2数值类型 #10

request101 opened this issue Jun 3, 2019 · 0 comments

Comments

@request101
Copy link

request101 commented Jun 3, 2019

#2.2.1 标准整型和长整型

a = 0o101
print("a="+str(a))
b=64
print('b='+str(b))
c=-237
print('c='+str(c))
d=0x80
print('d='+str(d))
e=-0x92
print('e='+str(e))
longint=34252456245724572456723
print('longint='+str(longint))
#1.2.2 布尔型和布尔对象
print(bool(1))
print(bool(True))
print(bool('0'))
print(bool([]))
print(bool((1,)))
foo = 42
bar = foo<42
print(bar)
print(bar+10)
print('%s' %bar)
print('%d' %bar)
#无_nozero_()
class C:pass
c=C()
print(bool(c))
#1.2.3 双精度浮点型
print(0.0)
print(-777.)
print(-5.555567119)
print(96e3 * 1.0)
print(-1.609E-19)
#1.2.4 复数
print(complex(2, 4))
print(1.23e-045+6.7e+089j)
#1.2.5 十进制浮点型
from decimal import *
print("十进制浮点....")
dec=Decimal('.1')
print(dec)
print(Decimal(.1))
print(dec +Decimal(.1))
#1.2.7转换工厂
print("转换工厂....")
print(int(4.2222222))
print(float(4))
print(complex(4)) #复数可以用complex(real,imag)
#1.2.8进制转换
print("进制转换...")
print(hex(255)) #整数类型转换十六进制
print(oct(255)) #整数类型转换八进制 
print(oct(0x111)) #十六进制转换八进制
#1.2.9ASII转换
print("进制转换....")
print(chr(76))  #数字转换字符型
print(ord('L'))  #字符型转换数字
#ceil()是不能直接访问的,需要导入 math 模块,通过静态对象调用该方法。(向上取整)
import math
print ("math.ceil(-45.17):" ,math.ceil(-45.17))
print("math.ceil(100.12):",math.ceil(100.12))
print("math.ceil(100.72):",math.ceil(100.72))
print("math.ceil(math.pi) : ", math.ceil(math.pi))
#floor(x) 返回数字的下舍整数,小于或等于 x。方法同ceil
import math
print("math.floor(-45.17):",math.floor(-45.17))
print("math.floor(100.12):",math.floor(100.12))
print("math.floor(100.72):",math.floor(100.72))
print("math.floor(math.pi):",math.floor(math.pi))
#fabs() 方法返回数字的绝对值
import math
print("math.floor(-45.17):",math.floor(-45.17))
print("math.floor(100.12):",math.floor(100.12))
print("math.floor(100.72):",math.floor(100.72))
print("math.floor(math.pi):",math.floor(math.pi))
#factorial (x),返回x的阶乘
import math
print("math.factorial(5):",math.factorial(5))
#hypot(),返回欧几里德范数 sqrt(x*x + y*y)。
import math
print("hypot(3,2):",math.hypot(3,2))
print("hypot(-3,3):",math.hypot(-3,3))
print("hypot(0,2):",math.hypot(0,2))
#sqrt(x) 方法返回数字x的平方根。
import math
print("math.sqrt(100):",math.sqrt(100))
print("math.sqrt(7):",math.sqrt(7))
print("math.sqrt(math.pi):",math.sqrt(math.pi))
#pow() 方法返回x的y次方的值。
import math 
print("pow(100,2):",math.pow(100,2))
print("math.pow(100,-2):",math.pow(100,-2))
print("math.pow(2,4):",math.pow(2,4))
print("math.pow(3,0):",math.pow(3,0))
#sqrt(x) x的算数平方根
import math 
print("math.sqrt(4):",math.sqrt(4))
print("math.sqrt(2):",math.sqrt(2))
#log(x) 方法返回x的自然对数,x > 0。 
import math
print("math.log(100.12):",math.log(100.12))
print("math.log(100.72):",math.log(100.72))
print("math.log(math.pi):",math.log(math.pi))
#log10() 方法返回以10为基数的x对数,x>0。
import math
print("math.log10(100.12):",math.log10(100.12))
print("math.log10(100.72):",math.log10(100.72))
print("math.log10(math.pi):",math.log10(math.pi))
#注意的是并不是舍弃小数部分,而是执行floor操作,trunc函数
import math
print("math.trunc(1/2):",math.trunc(1/2))
print("math.trunc(-1/2):",math.trunc(-1/2))
#isnan()函数的返回值是True或False。
import math
print("math.isnan(2):",math.isnan(2))
print("math.isnan(0.0):",math.isnan(0.0))
print("math.isnan(0.003):",math.isnan(0.007))
print("math.isnan(-25):",math.isnan(-25))
print("math.isnan(math.pi):",math.isnan(math.pi))
#degrees() 将弧度转换为角度。
import math
print("math.degress(3):",math.degrees(3))
print("math.degress(-3):",math.degrees(-3))
print("math.degress(0):",math.degrees(0))
print("math.degress(math.pi):",math.degrees(math.pi))
print("math.degress(math.pi/2):",math.degrees(math.pi/2))
print("math.degress(math.pi/4):",math.degrees(math.pi/4))
#radians() 方法将角度转换为弧度。
import math
print("math.radians(3):",math.radians(3))
print("math.radians(-3):",math.radians(-3))
print("math.radians(0):",math.radians(0))
print("math.radians(math.pi):",math.radians(math.pi))
print("math.radians(math.pi/2):",math.radians(math.pi/2))
print("math.radians(math.pi/4):",math.radians(math.pi/4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant