整数,浮点数

什么是整数,浮点数?

1整数   int类型
print(type(1000000))
print(type(2+3))
2.浮点数据:小数 类型:float
print(3.14)
print(type(5.66))   # 类型:float

3 py3下面的调整:结果是浮点小数(除法运算:/)

print(10/3)    # 3.3333333333333335
print(type(10/3))
print(type(9/3))
print(10//3)  # 地板除:取整
print(type(10//3))   # 类型:int
print(9//3)

4.科学计数法:

print(3.14e9)   # 3.14乘以10的9次方
print(type(3e8))  # 3乘以10的8次方--->应该是整数 (都是浮点)
# float
print(type(3))   # int
print(type(3.))  # float

5.复数数据类型:(用得很少:科学计算,工程学)

a = 3 + 4j
print(type(a))   # complex:实部和虚部
#做一个复数数据类型
b = complex(2, 5)   #
print(type(b))   # complex
#
print(b.real)  # complex对象的实部
print(b.imag)  # complex对象的虚部

6:布尔数据类型,

只有两个值:True(正确),False(错误)
书写的时候要首字母大写 (错误的写法:true,false)
条件表达式:and  or not
if 2 and 3:   # 2 and 3-->这部分是条件表达式,如果为True:执行后面的代码
    print(111)
if 2 and 0:   # 2 and 3-->这部分是条件表达式,如果为False:不执行后面的代码
    print(222)
#or:只有一个条件成立,最终的结果就为True
#0--->False     非0---->True  (2,3,5,6,1)

猜你喜欢

转载自www.cnblogs.com/java-my-leichuan/p/9244428.html