老男孩python全栈就业班第9期第1部分基础+模块+面向对象+网络编程第3天-数据类型int bool讲解及int bool str转化

int - 数字

i - 2
print(i.bit_length())

i - 3
print(i.bit_length())

i - 5
print(i.bit_length())

'''
                         bit length  
1    0000 0001    1
2    0000 0010    2
3    0000 0011    2

'''

 

bool - 布尔值

#int ------> str
i = 1
s = str(i)

#str -------> int
s = '123c'
i = int(s) #报错

s = '123'
i = int(s) #不报错

#int -------> bool
i = 3
b = bool(i)
print(b)

#bool -------> int
#True   1
#False  0

#str --------> bool
#非空字符串都是 True
#s = "" -----> False

s
if s:
    print('你输入的为空,请重新输入')
else:
    pass

#哪个效率高,第二个,因为 True 还要转换以下
while True:
    pass

while 1:
    pass

 

posted on 2019-11-07 09:35  herisson_pan  阅读(9)  评论(0)    收藏  举报

导航