请问python语言中的type函数有什么作用

更新时间:02-02 教程 由 冷兮め 分享

type就是指出指定对象的类型>>>a=1>>>type(a)>>>a='ABC'>>>type(a)>>>importtime>>>type(time)>>>a=time.time>>>type(a)>>>a=[]>>>type(a)>>>a={}>>>type(a)

bool是Boolean的缩写,只有真(True)和假(False)两种取值bool函数只有一个参数,并根据这个参数的值返回真或者假。1.当对数字使用bool函数时,0返回假(False),任何其他值都返回真。>>>bool(0)False>>>bool(1)True>>>bool(-1)True>>>bool(21334)True2.当对字符串使用bool函数时,对于没有值的字符串(也就是None或者空字符串)返回False,否则返回True。>>>bool('')False>>>bool(None)False>>>bool('asd')True>>>bool('hello')True3.bool函数对于空的列表,字典和元祖返回False,否则返回True。>>>a=[]>>>bool(a)False>>>a.append(1)>>>bool(a)True4.用bool函数来判断一个值是否已经被设置。>>>x=raw_input('Pleaseenteranumber:')Pleaseenteranumber:>>>bool(x.strip())False>>>x=raw_input('Pleaseenteranumber:')Pleaseenteranumber:4>>>bool(x.strip())True

声明:关于《请问python语言中的type函数有什么作用》以上内容仅供参考,若您的权利被侵害,请联系13825271@qq.com
本文网址:http://www.25820.com/tutorial/14_2105286.html