''' Welcome to LearnPython.NET File Name: PDataType.py Download from:https://www.learnpython.net/cn/python-code-samples.html Author: LearnPython.Net Editor: CoderChiu ''' #####布尔型##### #是否合法(默认为True); bValid = True #是否是救护车; bAmbulance = False print(bValid) print(type(bValid)) print(bAmbulance) print(type(bAmbulance)) #当前车速; nSpeed = 0 #道路限速80,小于等于80合法,当前速度79; bValid = 79 <= 80 print("If nSpeed = 79, bValid = ", bValid) print(type(bValid)) #不是救护车not 运算 bAmbulance = not True print("If not an Ambulance, bAmbulance = ", bAmbulance) #高速上小车道要求速度,大于60,小于120(and 运算) nSpeed = 81 bValid = (nSpeed >= 60) and (nSpeed <=120) print("If nSpeed = 81, bValid = " , bValid) #高速上如果是救护车,或者速度允许(or 运算) bAmbulance = True nSpeed = 125 bValid = bAmbulance or ((nSpeed >= 60) and (nSpeed <=120)) print("If an Ambulance nSpeed = 125, bValid = " , bValid) ######整数###### #年龄 nAge = 38 #楼层 nFloor = 3 #家庭人数 nPersonInFamily = 5 #看一下数据类型 print(type(nAge), type(nFloor), type(nFloor)) #####浮点数##### #身高(单位:米) fHeight = 1.72 #体重(单位:公斤) fWeight = 72.35 #雪糕的价格(单元:圆) fPriceOfIcecream = 3.5 #家庭月度用电量(单位:度) fDegreeOfPower = 357.6 #看一下数据类型 print(type(fHeight), type(fWeight), type(fPriceOfIcecream), type(fDegreeOfPower)) #####字符串##### #名字 strName = "Qiu Hongtao" #学校 strScheelName = "HIT" #家庭住址 strAddress ="Shenzhen, Baoan." #看一下数据类型 print(type(strName), type(strScheelName), type(strAddress)) #####类型转换##### #将体重精确到公斤; print(type(int(fWeight))) #把身高转换为字符串; print(type(str(fHeight))) #把年龄转换为浮点数 print(type(float(nAge)))