Python实践二

来源:互联网 发布:windows桌面更新黑屏 编辑:程序博客网 时间:2024/06/03 14:06
#======================11======================类型转换python提供了一些方法对数值进行类型转换:int(x) #把x转换成整数float(x) #把x转换成浮点数str(x) #把x转换成字符串bool(x) #把x转换成bool值栗子:num = 18print 'My age is ' + str(num) # My age is 18print 'your age is '+ str(28) # your age is 28print 'your had money %.2f' %float(3.3) #your had money 3.30print 'your had money %.2f' %float('3.3') #your had money 3.30print 'your had money %s' %float('6.6666') #your had money 6.6666print 'your had money %d' %float('6.6666') #your had money 6print '%d'  %int('123')# 123print '%d'  %int(444.123)  #  444print '%f'  %int(444.123)  #  444.000000print '%s'  %int(444.123)  #  444print '%d'  %int(num) #  18print '%d'  %bool(0)   # 0print '%d'  %bool(1)   # 1print '%d'  %bool('1') # 1print '%d'  %bool('0') # 1print '%s'  %bool(0)   # Falseprint '%s'  %bool(1)   # Trueprint '%s'  %bool('1') # Trueprint '%s'  %bool('0') # Trueprint '%s'  %bool('')  # Falseprint '%s'  %bool(' ') # True






0 0
原创粉丝点击